java - How do I properly add a 'Z' at the end of a datetime that's marshalled by Spring MVC with JAXB? -
I have a DateTimeXmlAdapter that I am using to convert Joda strings into strings. It looks like this:
Public class DateTimeXmlAdapter XmlAdapter extension & lt; String, DateTime & gt; {Private Stable Last String Pattern = "Yyen-MM-DD'THH: mm: SSZ"; Private stable last datetimeformer format = dateTime format.parten (petron); @ Override public datetime unskilled (string value) {return format. Paracetate Time (value); } @ Override public string martial (date time value) {return formatter.print (value); }}
This results in the following string in XML:
2014-10-16T18: 31: 57-0400
However, the end point I'm sending it to expect of a 'Z' instead of -0400 at the end. They recommend switching to UTC, so there is no need to send information from time to time. makes sense to me. However, I can not seem to come to the end of the 'jade' as long as I will tell it literally:
private static last string PATTERN = "yyyy-MM- Dd'THH: mm: ss'Z '";
The discussion below indicates that adding Z is not recommended.
Tried to change it in the following, but the result is 'z' in the date.
Public class DateTimeXmlAdapter XmlAdapter Extended & lt; String, DateTime & gt; {Private Static End Date Timeformer Format = ISODATTem FormatDate MinuteSecend () .ZentCity (); @ Override public datetime unskilled (string value) {return format. Paracetate Time (value); } @ Override public string martial (date time value) {return formatter.print (value); }}
Output:
2014-10-17T18: 50: 43
the end point saying I am They are talking about 'Z' because they indicate zero offset from UTC and what is the correct way to add a 'Z' when using JodaB and JAXB?
Thanks,
Matt
Use the method appropriate Not because this offset does not output (in your case this is Z = UTC + 00: 00). Instead, you can use the method, and of course you need to convert DateTime
-object to UTC-Offset:
Public class DateTimeXmlAdapter XmlAdapter extended Does & lt; String, DateTime & gt; {Personal Static Final Datimeformator Format = ISODATTM FormattedTime Name (.) With Zenancy (); @ Override public datetime unskilled (string value) {return format. Paracetate Time (value); } @ Override public string martial (date time value) {return formatter.print (value); }}
From the document:
returns a formatter that adds a complete date and time without a mill, which One is different from 't' (yyyy-MM-dd'T'HH: mm: ssZZ). Off zone offset is 'Z' for zero and '± HH: mm' for non-zero.
Comments
Post a Comment