简体   繁体   English

日期为XMLGregorianCalendar分隔符逗号(而不是点)

[英]Date to XMLGregorianCalendar separator comma instead of dot

I have the following problem: 我有以下问题:

I have converted a java.util.Date to XMLGregorianCalendar and the output has the following format: 我已经将java.util.Date转换为XMLGregorianCalendar ,并且输出具有以下格式:

2016-03-15T20:43:45.776+01:00

Instead I need: 相反,我需要:

2015-10-31T14:35:01,905+01:00

So any suggestions on how to change the . 因此,有关如何更改的任何建议. into , programmtically? 进入,编程方式? String replace is not an option because I need to pass the XMLGregorianCalendar object further. 不能使用字符串替换,因为我需要进一步传递XMLGregorianCalendar对象。

Any help would be greatly appreciated. 任何帮助将不胜感激。

The ISO-8601 -paper makes following statement: ISO-8601文件提出以下声明:

4.2.2.4 Representations with decimal fraction 4.2.2.4用小数表示

[...]If a decimal fraction is included, lower order time elements (if any) shall be omitted and the decimal fraction shall be divided from the integer part by the decimal sign specified in ISO 31-0, ie the comma [,] or full stop [.]. [...]如果包括小数部分,则应省略低阶时间元素(如果有),并且小数部分应从整数部分除以ISO 31-0中指定的小数点,即逗号[, ]或句号[。]。 Of these, the comma is the preferred sign.[...] 其中,逗号是首选符号。[...]

But XML-Schema says (as deviation) that only the dot is allowed in any lexical representation of its built-in time-related types (for example: xs:datetime or xs:time ). 但是XML-Schema表示(作为偏差),在其内置的与时间相关的类型的任何词法表示形式(例如xs:datetime或xs:time )中,只允许使用点。 And the Java-class XMLGregorianCalendar only models the built-in types so not permitting the comma as decimal sign. Java类XMLGregorianCalendar仅对内置类型建模,因此不允许逗号作为十进制符号。 This statement is also backed by the javadoc of the method DatatypeFactory.newXMLGregorianCalendar(String lexicalRepresentation) which points to the appropriate location in XML-Schema 1.0. 该语句还由DatatypeFactory.newXMLGregorianCalendar(String lexicalRepresentation)方法的javadoc支持,该javadoc指向XML-Schema 1.0中的适当位置。

So if your webservice requires the comma (but it should also be able to process a dot according to ISO-8601) then you cannot use XMLGregorianCalendar but have to use your own solution and probably custom user types in XML. 因此,如果您的Web服务需要逗号(但它也应该能够根据ISO-8601处理点),则您不能使用XMLGregorianCalendar而必须使用自己的解决方案以及可能的XML自定义用户类型。 Personally I think that the dot should be possible. 我个人认为该点应该是可能的。

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

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