首先我们看一下代码:
public static void timeZonePrint() {
LocalDateTime now = LocalDateTime.now();
// 获取秒数 gmt+8
Long second8 = now.toEpochSecond(ZoneOffset.of("+8"));
// 获取毫秒数 gmt+8
Long milliSecond8 = now.toInstant(ZoneOffset.of("+8")).toEpochMilli();
// 获取秒数 gmt+0
Long second0 = now.toEpochSecond(ZoneOffset.of("+0"));
// 获取毫秒数 gmt+0
Long milliSecond0 = now.toInstant(ZoneOffset.of("+0")).toEpochMilli();
// 获取秒数 currentTimeMillis
long totalMilliSeconds = System.currentTimeMillis();
TimeZone timeZone = TimeZone.getDefault();
System.out.println("System Default TimeZone: " + timeZone.getID());
System.out.println("now: " + now);
System.out.println("+8 second: " + second8);