I get a date as String like "start_date": "2013-07-05T11:32:00+00:00"
and need a date object, which represents it with hours and minutes.
If I use the format "yyyy-MM-dd'T'HH:mm:ss+HH:mm"
and sdf.parse(startDate)
, in the returned date object the hours and minutes are resetted.
But I need also hours and minutes for date comparison. How can I workaround this problem ?
You need the pattern "yyyy-MM-dd'T'HH:mm:ssXXX"
to parse your date. ("XXX"
stands for the timezone
)
In your case the second "HH:mm"
is resetting the values and using the last parsed data.
This part is the problem : +HH:mm
. You tell the parser that the part after the + sign is the hour and minutes part of the date, and these values are 00 and 00, so you get 0 and 0 as a result. The part startring at the + sign is in fact an offset to UTC time, and the symbol for that is XXX
(since Java 7).
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