Skip to content

Tag: java-time

Unable to parse date which is missing minutes?

I am trying to parse a date-time string that does not contain minutes 2019-10-12T07Z. When I run the above code, it throws the following exception stack trace Expected output Any idea what I should do? Answer You have to create custom DateTimeFormatter representing the time and offset. See that code run at Id…

Why LocalDateTime formatted with zone offset?

Consider code: The output is 2022-05-04-17 while UTC time is 2022-05-04-10. The documentation says that LocalDateTime is without zone offset – so why there is 7 hour shift? (My local time zone is +7UTC) Answer You’ve called LocalDateTime.now(), which is documented as (emphasis mine): Obtains the c…

How to parse DateTime with Time between the dates?

I want to parse a date-time variant that has the time in between the dates. Why is the following not working? Result: java.time.format.DateTimeParseException: Text ‘Tue Mar 1 01:29:47 2022’ could not be parsed at index 4 Answer I think you have to make sure that you provide a specific Locale for a…

Parse datetime with offset string to LocalDateTime

I am trying to parse following datetime String to LocalDateTimeObject, however I am not able to identify the format of the datetime string. Sat, 09 Oct 2021 02:10:23 -0400 How should I determine the pattern of the above string? Answer You should first check if the date string matches any of the Predefined For…