简体   繁体   English

如何在Apache CXF Web服务中更改日期时间格式

[英]How to change the datetime format in Apache CXF web services

I have created some element names with dateTime type and date type also, I have mentioned the date and dateTime in jaxb Bindings.xml file with Global scope, Its working fine. 我还创建了一些具有dateTime类型和date类型的元素名称,我在具有全局范围的jaxb Bindings.xml文件中提到了date和dateTime,它的工作正常。 Jaxb bindings.xml file Jaxb bindings.xml文件

<jaxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <jaxb:globalBindings generateIsSetMethod="true" fixedAttributeAsConstantProperty="true" localScoping="toplevel" generateElementProperty="false" collectionType="indexed">
        <jaxb:javaType name="java.util.Calendar" xmlType="xs:date" parseMethod="javax.xml.bind.DatatypeConverter.parseDate" printMethod="javax.xml.bind.DatatypeConverter.printDate" />
        <jaxb:javaType name="java.util.Calendar" xmlType="xs:dateTime" parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime" printMethod="javax.xml.bind.DatatypeConverter.printDateTime" />
        <xjc:serializable uid="1" />
    </jaxb:globalBindings>
</jaxb:bindings>

I am getting the out put for all the elements. 我正在考虑所有要素。 But it's not showing proper response dateTime in desire way. 但是它没有以期望的方式显示正确的响应dateTime。

Its showing like this 像这样显示

2014-09-11T03:58:25+05:30

But I want with milleseconds also like 但我想要毫秒也喜欢

2014-09-11T03:58:25.000+05:30  

there is no much different just mille seconds are missing in current out put how do it. 没有什么不同,只是电流输出丢失了毫秒。 In which class I need to override or write new method for this. 我需要在哪个类中重写或编写新方法。

  • Implement your converter as static print / parse methods - or better implement an adapter (subclass XmlAdapter ). 将您的转换器实现为静态print / parse方法-或更佳地实现适配器(子类XmlAdapter )。
  • Use jaxb:javaType or (better) xjc:javaType customization to configure your adapter. 使用jaxb:javaType或(更好) xjc:javaType定制来配置适配器。 See the following question for example: 例如,请参见以下问题:

Set an XJC javaType adapter in external binding file 在外部绑定文件中设置XJC javaType适配器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM