Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

date format parses the 12th hour value (hh) to 00

Tags:

java

date

date format parses the 12th-hour value (hh) to 00 while applying the format as "yyyy-MM-dd'T'hh:mm:ss" but it does not parse the 13th hour to 1 PM. PFB the sample code piece.

Date testDate = DateUtil.parse("yyyy-MM-dd'T'hh:mm:ss", "2010-07-09T12:50:58");

can you please let me know why this is converting so?

like image 395
jayanthi bala Avatar asked Oct 20 '25 09:10

jayanthi bala


1 Answers

You should use HH instead of hh. The former is for 24-hour clock, the latter for a 12-hour clock.

See the javadoc for SimpleDateFormat.

EDIT: Note that the problem may be at the other end too. To get the hour from a java.util.Date, you can set it on a Calendar object and call get(Calendar.HOUR_OF_DAY). Note that get(Calendar.HOUR) will give you the 12-hour rather than the 24-hour.

like image 186
Simon Nickerson Avatar answered Oct 21 '25 22:10

Simon Nickerson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!