Convert the LocalDateTime unit to the Instant type of the given offset and print that unit combined with the number of seconds passed since the Java epoch.
Computer scienceProgramming languagesJavaAdditional instrumentsEssential standard classesDate and time
ZonedDateTime and OffsetDateTime
Get the Instant of the ZonedDateTime
Report a typo
Sample Input 1:
4Sample Output 1:
1991-04-15T11:00:00Z, toEpochSeconds: 671713200Write a program in Java 17
import java.util.Scanner;
import java.time.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
LocalDateTime localDateTime = LocalDateTime.of(1991, 4, 15, 15, 0);
Instant instant = convertToInstant(localDateTime, scanner.nextInt());
System.out.println(String.format("%s, toEpochSeconds: %d", instant, instant.getEpochSecond()));
}
public static Instant convertToInstant(LocalDateTime localDateTime, int hours) {
}
}
___
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.