I converted DateString of format YYYY-mm-DD HH:MM:SS
in my JSON and persisted to POJO using the code
DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
this.startDate = format.parseDateTime(startDate);
When I convert the POJO back to JSON, the date is written like 2013-07-12T18:31:01.000Z
.
How do we parse the time string 2013-07-12T18:31:01.000Z
back to JodaDateTime object. What should be the formatter.
I used YYYY-mm-DD HH:MM:SS
and it didn't work
How to change the SimpleDateFormat to jodatime? String s = "2014-01-15T14:23:50.026"; DateTimeFormatter dtf = DateTimeFormat. forPattern("yyyy-MM-dd'T'HH:mm:ss. SSSS"); DateTime instant = dtf.
2013-07-12T18:31:01.000Z
it is standart ISO date time format.
You can use standart Joda date time formatter ISODateTimeFormat::dateTime()
Example:
String startDate = "2013-07-12T18:31:01.000Z";
DateTime dt = ISODateTimeFormat.dateTime().parseDateTime(startDate);
in this case date will be converted to date in your time zone.
If you want ignore your time zone use UTC
zone in formatter:
String startDate = "2013-07-12T18:31:01.000Z";
DateTime dt = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC).parseDateTime(startDate);
You should append X
to your pattern. The SimpleDateFormat
API contains a full list of fields you can use in a DateFormat
, including X
for "ISO 8601 time zone".
An ISO 8601 time zone is specified as
The number of pattern letters designates the format for both formatting and parsing as follows:
ISO8601TimeZone: OneLetterISO8601TimeZone TwoLetterISO8601TimeZone ThreeLetterISO8601TimeZone OneLetterISO8601TimeZone: Sign TwoDigitHours Z TwoLetterISO8601TimeZone: Sign TwoDigitHours Minutes Z ThreeLetterISO8601TimeZone: Sign TwoDigitHours : Minutes Z
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With