SteelReed

Search

Search posts, questions…

Java CoreQuestion 37 / 43

Junior

Does a Unix timestamp depend on the time zone? When do you use Instant and when LocalDate?

Short answer

A Unix timestamp does not depend on time zones: it is the number of seconds since 1970-01-01T00:00:00Z, an absolute moment. Time zones only change how it is displayed.

shown at +07:00shown in UTCtoInstant()Unix timestamp16956336522023-09-25T16:20:52+07:002023-09-25T09:20:52Zthe same Instant

3 points to say:

  1. Events like createdAt, logs, token expiry use Instant.
  2. Calendar dates like birthdays use LocalDate.
  3. Compare moments with isEqual or Instant.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.