public class Solution {
public static void main(String[] args) {
ZoneId zone1 = ZoneId.of("Zulu");
ZoneId zone2 = ZoneId.of("Etc/GMT+8");
System.out.println(ZonedDateTime.now(zone1));
System.out.println(ZonedDateTime.now(zone2));
LocalDateTime time = changeZone(LocalDateTime.of(2020, 3, 19, 1, 40), zone1, zone2);
System.out.println(time);
}
static LocalDateTime changeZone(LocalDateTime fromDateTime, ZoneId fromZone, ZoneId toZone) {
ZonedDateTime from1 = ZonedDateTime.now(fromZone);
ZonedDateTime to1 = ZonedDateTime.now(toZone);
return fromDateTime.minusHours(from1.getHour()- to1.getHour());
}
}
package com.javarush.task.pro.task16.task1618;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
/*
Лишь бы не запутаться
*/
public class Solution {
public static void main(String[] args) {
ZoneId zone1 = ZoneId.of("Zulu");
ZoneId zone2 = ZoneId.of("Etc/GMT+8");
System.out.println(ZonedDateTime.now(zone1));
System.out.println(ZonedDateTime.now(zone2));
LocalDateTime time = changeZone(LocalDateTime.of(2020, 3, 19, 1, 40), zone1, zone2);
System.out.println(time);
}
static LocalDateTime changeZone(LocalDateTime fromDateTime, ZoneId fromZone, ZoneId toZone) {
ZonedDateTime from1 = ZonedDateTime.now(fromZone);
ZonedDateTime to1 = ZonedDateTime.now(toZone);
LocalDateTime a = fromDateTime.minusHours(from1.getHour()- to1.getHour());
return a;
}
}