вроде же ответ даёт правильный, почему валидатор не принимает ? .
package com.javarush.task.pro.task16.task1618;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
/*
Лишь бы не запутаться
*/
/*
Лишь бы не запутаться
Можно ли, зная время в одном часовом поясе, определить время в другом?
Реши эту задачу в методе changeZone.
Его параметры: fromTime - известное время;
fromZone - временная зона, в которой известно время;
toZone - временная зона, в которой нужно определить время.
Requirements:
1. Метод changeZone должен вернуть LocalDateTime во временной зоне toZone.
*/
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 time1 = ZonedDateTime.now(fromZone);
ZonedDateTime time2 = ZonedDateTime.now(toZone);
int ty1 = time1.getYear();
int tMV1 = time1. getMonthValue();
int tD1 = time1. getDayOfMonth();
int th1= time1.getHour();
int tm1 = time1.getMinute();
int ts1 = time1. getSecond();
int ty2 = time2.getYear();
int tMV2 = time2. getMonthValue();
int tD2 = time2. getDayOfMonth();
int th2= time2.getHour();
int tm2 = time2.getMinute();
int ts2 = time2. getSecond();
int ty0 = ty2 - ty1;
int tMV0 = tMV2 - tMV1;
int tD0 = tD2-tD1;
int th0= th2 - th1;
int tm0 = tm2-tm1;
int ts0 = ts2-ts1;
return fromDateTime.plusYears(ty0).plusMonths(tMV0).plusDays(tD0).plusHours(th0).plusMinutes(tm0).plusSeconds(ts0);
}
}