Last active
July 13, 2018 09:39
-
-
Save perforb/e7f4e608444879d1e200998900ceafbc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.todo.common.datetime; | |
import java.time.Clock; | |
import java.time.ZoneId; | |
import java.time.ZonedDateTime; | |
public class ClockTimeTest { | |
public static void main(String[] args) { | |
Clock utc = Clock.systemUTC(); | |
System.out.printf("clock: %s\n", utc); | |
System.out.printf("zone: %s\n", utc.getZone()); | |
System.out.printf("ZonedDateTime.now: %s\n", ZonedDateTime.now(utc)); | |
System.out.printf("clock.instant: %s\n", utc.instant()); | |
System.out.printf("clock.instant.toEpochMilli: %s\n", utc.instant().toEpochMilli()); | |
System.out.println(); | |
Clock tokyo = Clock.system(ZoneId.of("Asia/Tokyo")); | |
System.out.printf("clock: %s\n", tokyo); | |
System.out.printf("zone: %s\n", tokyo.getZone()); | |
System.out.printf("ZonedDateTime.now: %s\n", ZonedDateTime.now(tokyo)); | |
System.out.printf("clock.instant: %s\n", tokyo.instant()); | |
System.out.printf("clock.instant.toEpochMilli: %s\n", tokyo.instant().toEpochMilli()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clock: SystemClock[Z] | |
zone: Z | |
ZonedDateTime.now: 2018-07-13T09:36:59.612Z | |
clock.instant: 2018-07-13T09:36:59.616Z | |
clock.instant.toEpochMilli: 1531474619695 | |
clock: SystemClock[Asia/Tokyo] | |
zone: Asia/Tokyo | |
ZonedDateTime.now: 2018-07-13T18:36:59.702+09:00[Asia/Tokyo] | |
clock.instant: 2018-07-13T09:36:59.703Z | |
clock.instant.toEpochMilli: 1531474619703 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment