Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
40 lines (28 loc) · 1.85 KB
/
Copy pathMain.java
File metadata and controls
40 lines (28 loc) · 1.85 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
31
32
33
34
35
36
37
38
39
40
package modern.challenge;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
public class Main {
public static void main(String[] args) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm a, MMM dd, yyyy");
DateTimeFormatter zoneFormatter = DateTimeFormatter.ofPattern("hh:mm a, MMM dd, yyyy Z VV");
LocalDateTime ldt = LocalDateTime.of(2019, Month.FEBRUARY, 26, 16, 00);
System.out.println("Perth LocalDateTime: " + ldt.format(formatter)
+ " | Scheduled Flight Time: 15 hours and 30 minutes\n");
ZonedDateTime auPerthDepart = ldt.atZone(ZoneId.of("Australia/Perth"));
ZonedDateTime euBucharestDepart = auPerthDepart.withZoneSameInstant(ZoneId.of("Europe/Bucharest"));
ZonedDateTime auPerthArrive = auPerthDepart.plusHours(15).plusMinutes(30);
ZonedDateTime euBucharestArrive = auPerthArrive.withZoneSameInstant(ZoneId.of("Europe/Bucharest"));
OffsetDateTime utcAtDepart = auPerthDepart.withZoneSameInstant(ZoneId.of("UTC")).toOffsetDateTime();
OffsetDateTime utcAtArrive = auPerthArrive.withZoneSameInstant(ZoneId.of("UTC")).toOffsetDateTime();
System.out.println("UTC time at depart is: " + utcAtDepart.format(formatter));
System.out.println("UTC time at arrive is: " + utcAtArrive.format(formatter));
System.out.println("\nAt depart, in Perth is: " + auPerthDepart.format(zoneFormatter));
System.out.println("At arrive, in Perth is: " + auPerthArrive.format(zoneFormatter));
System.out.println("\nAt depart, in Bucharest is: " + euBucharestDepart.format(zoneFormatter));
System.out.println("At arrive, in Bucharest is: " + euBucharestArrive.format(zoneFormatter));
}
}