Index

Java date time

epoch timestamp to Instant
Instant epochInstant = Instant.ofEpochSecond(0);
System.out.println("instant:" + epochInstant);
Instant to epoch timestamp
System.out.println(epochInstant.toEpochMilli());
get system time zone ZoneId
ZoneId zoneId = ZoneOffset.systemDefault();
System.out.println(zoneId);
get associated TimeZone
TimeZone zone = TimeZone.getTimeZone(zoneId);
System.out.println(zone);
System.out.println(zone.getOffset(0));
epoch Instant to ZonedDateTime
ZonedDateTime zdt = epochInstant.atZone(zoneId);
System.out.println(zdt);
ZonedDateTime to epoch timestamp
long zdtt = zdt.toEpochSecond();
System.out.println(zdtt);
java.util.Date to UTC timestamp correcting for TimeZone
Date date = new Date();
int utc = date.getTime() + zone.getOffset(TimeZone.getTimeZone(ZoneOffset.systemDefault()))