fork download
  1. import java.time.LocalDateTime;
  2. import java.time.LocalTime;
  3. import java.time.ZoneId;
  4. import java.time.ZonedDateTime;
  5.  
  6. public class Main {
  7. public static void main(String[] args) {
  8. // Change the JVM's ZoneId, ZoneId.systemDefault() with the applicable ZoneId
  9. // e.g. ZoneId.of("America/Los_Angeles")
  10. ZoneId zoneId = ZoneId.systemDefault();
  11.  
  12. ZonedDateTime zdt = ZonedDateTime.now(zoneId);
  13. System.out.println(zdt.getHour());
  14.  
  15. LocalDateTime ldt = LocalDateTime.now(zoneId);
  16. System.out.println(ldt.getHour());
  17.  
  18. LocalTime time = LocalTime.now(zoneId);
  19. System.out.println(time.getHour());
  20. }
  21. }
Success #stdin #stdout 0.1s 48204KB
stdin
Standard input is empty
stdout
12
12
12