Skip to content
Advertisement

Tag: java-time

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 current date-time from the system clock in the default time-zone. This will query the

Java Instant.parse cannot validate date

I have an instant field and trying to validate the values in this field using the following approach: Instant.parse(“2021-09-29 09:35:07.531”) However, it throws the error: java.time.format.DateTimeParseException: Text ‘2021-09-29 09:35:07.531’ could not be parsed at index 10. So, how can I test if the given Instant date in String format is a valid Instant date? I am implementing an Import feature

Create a DateTimeFormater with an Optional Section at Beginning

I have timecodes with this structure hh:mm:ss.SSS for which i have a own Class, implementing the Temporal Interface. It has the custom Field TimecodeHour Field allowing values greater than 23 for hour. I want to parse with DateTimeFormatter. The hour value is optional (can be omitted, and hours can be greater than 24); as RegEx (d*dd:)?dd:dd.ddd For the purpose of

DateTimeFormatter – Strict vs Lenient unexpected behaviour

I have some text that is only being parsed by a DateTimeFormatter when the parse style is Strict – and not when it’s Lenient. This seems like the opposite behaviour to what I’d expect? Example: Output: Answer Having posted this as a bug – https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8228353 I got the following reply: According to DateTimeFormatterBuilder’s spec, appendPattern(“yy”) translates to appendValueReduced(ChronoField.YEAR_OF_ERA, 2, 2000),

What’s the difference between ZonedDateTime and OffsetDateTime?

I’ve read the documentation, but I still can’t get when I should use one or the other: OffsetDateTime ZonedDateTime According to documentation OffsetDateTime should be used when writing date to database, but I don’t get why. Answer Q: What’s the difference between java 8 ZonedDateTime and OffsetDateTime? The javadocs say this: “OffsetDateTime, ZonedDateTime and Instant all store an instant on

Advertisement