Weird Difference in Timezone offset for & xsd:dateTime


I have an issue with formatting Timezone offset for XML transmission. returns the timezone offset as “+0100”.

But in the XSD for the XML to be transferred the format is required as “+01:00”.

Is there a convenient way to format this without doing some substring/concat stuff?



The issue stems from the difference in the way Java describes timezone offsets and the way XML Schema describes them. returns the offset in Java format.

I don’t know of a built-in way that will do this for you. I have a utility service that gets the offset, splits it into hours and minutes, adds the colon and then appends it to the XML formatted time.

Any service that needs a time in W3C XML Schema dateTime format just calls that utility service instead of I also provided an optional timezone format in case it was necessary to express the XML time relative to a specific timezone.



The accepts three parameters: pattern, timezone and locale.

If you need a numeric timezone offset in your XML schema dateTime in the format of [+|-]hh:mm you will need to start with a “pattern” of yyyy-MM-dd’T’HH:mm:ss.SSSZ and then write some extra code to insert a colon character “:” between the offset hours digits and offset minutes digits.

If you want to use the “trailing Z” form of the XML schema dateTime, you can use the pattern yyyy-MM-dd’T’HH:mm:ss.SSS’Z’.

Note: Be sure to use a capital “H” to represent the hours position. If you use a lower case “h” for hours, you will only be able to represent times prior to 1:00 PM correctly.


Hi Mark,

this is exactly the way how we implemented this transformation.

The issue is that there is no out-of-the-box function to get the format like it is required by XML.