I am executing following code which gives me
"Exception in thread "main" org.joda.time.IllegalFieldValueException: Cannot parse "12/17/2017 23:10": Value 23 for clockhourOfHalfday must be in the range [1,12]"
DateTimeFormatter dt = DateTimeFormat.forPattern("MM/dd/yyyy hh:mm");
System.out.println(dt.parseDateTime("12/17/2017 23:10"));
If I will parse "12/17/2017 02:10"
then It executes successfully.
So basically, I need to parse time having 24hr clock format.
Thanks in advance.
h
is for halfday in JodaTime as you can see in the exception.
You need to use H
(or possibly k
):
DateTimeFormatter dt = DateTimeFormat.forPattern("MM/dd/yyyy HH:mm");
System.out.println(dt.parseDateTime("12/17/2017 23:10"));
There is more information in the DateTimeFormat API.
It can be achieved with Simple Date Format too.
DateFormat readDate = new SimpleDateFormat( "MM/dd/yyyy HH:mm");
Date date = readDate.parse("12/17/2017 23:10");
DateFormat writeDate = new SimpleDateFormat( "MM/dd/yyyy HH:mm");
System.out.println(writeDate.format(date));
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