forked from igor-baiborodine/java-various-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeZonesExample.java
More file actions
30 lines (22 loc) · 1.02 KB
/
TimeZonesExample.java
File metadata and controls
30 lines (22 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.kiroule.ocpupgradejava8.topic8_2;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
/**
* @author Igor Baiborodine
*/
public class TimeZonesExample {
public static void main(String... args) {
LocalDateTime nowDateTime = LocalDateTime.now();
ZoneId montrealZone = ZoneId.of("America/Montreal");
ZonedDateTime montrealZonedDateTime = ZonedDateTime.of(nowDateTime, montrealZone);
System.out.printf("Montreal-zoned now date/time: %s %n", montrealZonedDateTime);
ZoneId moscowZone = ZoneId.of("Europe/Moscow");
ZonedDateTime moscowZonedDateTime = montrealZonedDateTime.withZoneSameInstant(moscowZone);
System.out.printf("Moscow-zoned now date/time: %s %n", moscowZonedDateTime);
// Typically the amount is zero during winter and one hour during summer.
System.out.printf("Current daylight savings offset for [%s]: %s %n",
moscowZone, moscowZone.getRules().getDaylightSavings(Instant.now()));
}
}