How to parse "YYYY-MM-DD" with joda time

I am trying to use joda-time to parse a form date string YYYY-MM-DD. I have a test code:

DateTimeFormatter dateDecoder = DateTimeFormat.forPattern("YYYY-MM-DD");
DateTime dateTime = dateDecoder.parseDateTime("2005-07-30");

System.out.println(dateTime);

What outputs:

2005-01-30T00:00:00.000Z

As you can see, the created object DateTimehas a value 30 Jan 2005instead 30 July 2005.

Appreciate any help. I just assumed that this would work because it is one of the date formats listed here .

+4
source share
3 answers

The confusion is that it actually has an ISO format. YYYY-MM-DDnot an ISO format, the actual total date.

, 2005-07-30 ISO-8601, YYYY-MM-DD . YYYY-MM-DD . , , , , , 2- , , .

, $year4-$month2-$day2, .

, "Y" "y" "D" "d".

.

+5

, w3 JodaTime DateTimeFormat, .

, DateTimeFormat DD Day in year, DD 30 - 30- , .. 30 . String, 07. , 01 .

, DateTimeFormat, , w3 dat time.

DateTimeFormatter dateDecoder = DateTimeFormat.forPattern("yyyy-MM-dd");
+3

All Articles