fork download
  1. import java.time.LocalDate;
  2. import java.time.LocalDateTime;
  3. import java.time.LocalTime;
  4. import java.time.Month;
  5. import java.time.ZoneId;
  6. import java.time.ZonedDateTime;
  7.  
  8. public class Main {
  9. public static void main(String[] args) {
  10. LocalTime time = LocalTime.of(10, 20);
  11. ZoneId zoneId = ZoneId.of("Europe/London");
  12.  
  13. System.out.println(ZonedDateTime.of(LocalDate.of(2021, Month.MARCH, 27), time, zoneId));
  14. System.out.println(ZonedDateTime.of(LocalDate.of(2021, Month.MARCH, 28), time, zoneId));
  15.  
  16. // ############# Obtaining timezone offset from ZoneId #############
  17. LocalDateTime ldt = LocalDateTime.of(LocalDate.of(2021, Month.MARCH, 28), time);
  18.  
  19. System.out.println(ZonedDateTime.of(ldt, zoneId).getOffset());
  20. // Alternatively
  21. System.out.println(zoneId.getRules().getOffset(ldt));
  22. }
  23. }
Success #stdin #stdout 0.1s 55632KB
stdin
Standard input is empty
stdout
2021-03-27T10:20Z[Europe/London]
2021-03-28T10:20+01:00[Europe/London]
+01:00
+01:00