简体   繁体   中英

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:

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.

Any help would be greatly appreciated.

The ISO-8601 -paper makes following statement:

4.2.2.4 Representations with decimal fraction

[...]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 [.]. 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 ). And the Java-class XMLGregorianCalendar only models the built-in types so not permitting the comma as decimal sign. 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.

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. Personally I think that the dot should be possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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