首页javajaxbJava HTML/XML - 如何控制JAXB在XML生成后的dateTime格式

Java HTML/XML - 如何控制JAXB在XML生成后的dateTime格式

我们想知道如何控制JAXB在XML生成后的dateTime格式。
import java.util.Calendar;
import java.util.TimeZone;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

public class Main {

  public static void main(String[] args) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(Root.class);

    Root root = new Root();
    root.defaultTimeZone = Calendar.getInstance();

    root.setTimeZone = Calendar.getInstance();
    root.setTimeZone.setTimeZone(TimeZone.getTimeZone("GMT"));

    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(root, System.out);
  }

  @XmlRootElement
  @XmlAccessorType(XmlAccessType.FIELD)
  public static class Root {

    Calendar defaultTimeZone;
    Calendar setTimeZone;

  }
}