The java.time API
Modern Java date-time APIs separate date, local date-time, instant, offset, and time zone.
Instant now = Instant.now();
LocalDate today = LocalDate.now();
ZonedDateTime india =
ZonedDateTime.now(ZoneId.of("Asia/Kolkata"));
Duration duration = Duration.between(
now, now.plusSeconds(30)
);
Use Instant for machine-oriented points in time, LocalDate for a date without a zone, and ZonedDateTime when location matters.
For financial systems, BigDecimal is generally preferred when decimal arithmetic must be exact.
Time zones are business data
A timestamp without its intended time-zone semantics can be ambiguous.
Key Takeaways
- Use
java.timefor new code. - Use
Instantfor absolute points in time. - Use explicit zones for human/business-local schedules.