Home > Blockchain >  Local Date Parsing 2021-06-07 03:00
Local Date Parsing 2021-06-07 03:00

Time:05-05

How can I parse this code to localDate?

DateTimeParseException: Text '2021-06-07 03:00' could not be parsed at index 10

I have tried both DateTimeFormatter.ISO_ZONED_DATE_TIME and DateTimeFormatter.ofPattern("yyyyMMdd"). these are not work.

Do u you have any suggestions?

CodePudding user response:

May be something like this?

String dt="2021-06-07 03:00";
DateTimeFormatter dateTimeFormatter= DateTimeFormatter.ISO_DATE;
System.out.println(dateTimeFormatter.parse(dt).get(ChronoField.OFFSET_SECONDS));
System.out.println(dateTimeFormatter.parse(dt).get(ChronoField.DAY_OF_YEAR));

Output:

Offset seconds: 10800
Day of year:158
  • Related