【问题标题】:XMLBeans dates without timezone information没有时区信息的 XMLBeans 日期
【发布时间】:2014-07-05 04:02:34
【问题描述】:

这个问题与: XmlBeans XmlDateTime format without timezone info

但我需要在没有任何时区信息的情况下在 XMLBeans 中打印日期。 我从万维网联盟读到的是:

“日期对象”是具有年、月和日属性的对象 像那些 dateTime 对象,加上一个 optional 时区值 时区属性

http://www.w3.org/TR/xmlschema-2/#date

关键字是可选。我需要从默认 XMLBeans 行为中删除它。

我尝试过的:

XmlDateTime xmlDateTime = XmlDateTime.Factory.newInstance();
xmlDateTime.setCalendarValue(new GregorianCalendar());
GDateBuilder gdb = new GDateBuilder(xmlDateTime.getDateValue());
gdb.normalize();
xmlDateTime.setGDateValue(gdb.toGDate());
instruction.setReqdExctnDt(gdb.getCalendar());
CBIPartyIdentification4 partyId = CBIPartyIdentification4.Factory.newInstance();

我得到的是2014-05-16Z 我需要的是2014-05-16。

我该怎么做?

【问题讨论】:

    标签: java xml datetime xsd xmlbeans


    【解决方案1】:

    使用 XmlCalendar 类,它不会添加时区信息:

    XmlDateTime xmlDateTime = XmlDateTime.Factory.newInstance();
    Calendar xmlCalendar = new XmlCalendar();
    xmlCalendar.set(Calendar.YEAR, 2014);
    xmlCalendar.set(Calendar.MONTH, 2);
    xmlCalendar.set(Calendar.DATE, 22);
    xmlDateTime.setCalendarValue(xmlCalendar);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-23
      • 1970-01-01
      • 2018-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-05
      相关资源
      最近更新 更多