Home » Android » java – SimpleDateFormat 24h

java – SimpleDateFormat 24h

Posted by: admin April 23, 2020 Leave a comment

Questions:

I’ve got a SimpleDateFormat to parse a String into a Date:

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ");

When I’m parsing this:

format.parse("2011-08-29T12:44:00+0200");

The result will be, when using Date.toLocaleString:

29 aug. 2011 00:44:00

This should be ofcourse:

29 aug. 2011 12:44:00

And when I’m parsing this:

format.parse("2011-08-29T13:44:00+0200");

Then the result is as expected:

29 aug. 2011 13:44:00

How can I fix this?

How to&Answers:

Use HH instead of hh for the hours pattern:

H   Hour in day (0-23)  Number  0
k   Hour in day (1-24)  Number  24
K   Hour in am/pm (0-11)    Number  0
h   Hour in am/pm (1-12)    Number  12