Java Zero to All All questionsPractise free
Interview questions › Java Foundations — Zero to Basics › Java 8 — Optional, Date/Time API, Method Refs

Why is using the wrong temporal type (e.g., LocalDateTime for a timestamp) a production hazard?

Level III · MidJava 8 — Optional, Date/Time API, Method Refs
Short answer

LocalDateTime has no timezone or offset, so it's ambiguous on the absolute timeline — store an event with it and you can't tell what real instant it happened across servers in different zones, and DST transitions make some local times nonexistent or doubled.

Explanation

For an actual moment in time use Instant (or store epoch millis/timestamptz), and only use LocalDate/LocalDateTime for genuinely zoneless concepts like a birthday or a store's opening time. Mixing these up causes off-by-hours bugs that only appear around DST boundaries or for users in other regions.

Common mistakes
  • Storing event timestamps as LocalDateTime without a zone.
  • Converting between time zones manually instead of using ZonedDateTime or Instant.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for Java 8 — Optional, Date/Time API, Method Refs.

Practise free

More on Java 8 — Optional, Date/Time API, Method Refs