Compare how many hours will pass from the date-time represented by the ZonedDateTime variable until that represented by the OffsetDateTime variable.
Computer scienceProgramming languagesJavaAdditional instrumentsEssential standard classesDate and time
ZonedDateTime and OffsetDateTime
The until() method
Report a typo
Sample Input 1:
1995
5
21
13
0Sample Output 1:
35928Write a program in Java 17
import java.util.Scanner;
import java.time.*;
import java.time.temporal.ChronoUnit;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ZoneId yerevanZone = ZoneId.of("Asia/Yerevan");
ZoneOffset yerevanOffset = ZoneOffset.of("+04:00");
LocalDateTime localDateTime1 = LocalDateTime.of(1991, 4, 15, 13, 0);
LocalDateTime localDateTime2 = createLocalDateTime(scanner);
ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime1, yerevanZone);
OffsetDateTime offsetDateTime = OffsetDateTime.of(localDateTime2, yerevanOffset);
System.out.println(getHoursUntil(zonedDateTime, offsetDateTime));
}
public static LocalDateTime createLocalDateTime(Scanner scanner) {
int year = scanner.nextInt();
int month = scanner.nextInt();
int dayOfMonth = scanner.nextInt();
int hour = scanner.nextInt();
int minute = scanner.nextInt();
return LocalDateTime.of(year, month, dayOfMonth, hour, minute);
}
public static long getHoursUntil(ZonedDateTime zonedDateTime, OffsetDateTime offsetDateTime) {
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.