Skip to content

Instantly share code, notes, and snippets.

@perforb
Created December 10, 2018 01:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save perforb/fa5fb9b8b0161e819015470df24bbc39 to your computer and use it in GitHub Desktop.
public static void main(String[] args) {
Instant instant = Instant.ofEpochMilli(System.currentTimeMillis());
String timeZone1 = ZoneId.SHORT_IDS.get("CST");
String timeZone2 = ZoneId.SHORT_IDS.get("JST");
String timeZone3 = "UTC";
ZonedDateTime zonedDateTime1 = ZonedDateTime.ofInstant(instant, ZoneId.of(timeZone1));
ZonedDateTime zonedDateTime2 = ZonedDateTime.ofInstant(instant, ZoneId.of(timeZone2));
ZonedDateTime zonedDateTime3 = ZonedDateTime.ofInstant(instant, ZoneId.of(timeZone3));
System.out.println(String.format("%2s:%2s %s", zonedDateTime1.getHour(), zonedDateTime1.getMinute(), zonedDateTime1));
System.out.println(String.format("%2s:%2s %s", zonedDateTime2.getHour(), zonedDateTime2.getMinute(), zonedDateTime2));
System.out.println(String.format("%2s:%2s %s", zonedDateTime3.getHour(), zonedDateTime3.getMinute(), zonedDateTime3));
}
19:53 2018-12-09T19:53:43.916-06:00[America/Chicago]
10:53 2018-12-10T10:53:43.916+09:00[Asia/Tokyo]
1:53 2018-12-10T01:53:43.916Z[UTC]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment