Memra

Instant, Duration, Period & ZonedDateTime

Machine timestamps, time-based gaps, date-based gaps, and timezone-aware datetimes.

Four more time types

Instant represents a single point on the UTC timeline — a machine timestamp:

Instant now  = Instant.now();
Instant past = Instant.ofEpochSecond(0);  // 1970-01-01T00:00:00Z

Duration measures an amount of time in hours, minutes, seconds, nanoseconds — precise and time-based:

Duration d = Duration.between(start, end);  // between two Instants/LocalTimes
long secs  = d.getSeconds();

Period measures an amount of time in years, months, days — calendar-based:

Period p    = Period.between(birthday, today);  // between two LocalDates
int years   = p.getYears();
int months  = p.getMonths();

ZonedDateTime is a LocalDateTime plus a ZoneId — use it whenever you need to deal with different time zones:

ZoneId       london = ZoneId.of("Europe/London");
ZonedDateTime zdt   = ZonedDateTime.now(london);
ZonedDateTime converted = zdt.withZoneSameInstant(ZoneId.of("America/New_York"));

The ZoneId.of(...) string is an IANA time zone name — always use named zones, never offsets like "+01:00", unless you genuinely mean a fixed offset.

NORMAL ~/memra/learn/java-from-zero/instant-duration-period-zone utf-8 LF