fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.* ;
  8. import java.time.format.* ;
  9. import java.time.temporal.* ;
  10. import java.time.chrono.* ;
  11. import java.time.zone.* ;
  12.  
  13. /* Name of the class has to be "Main" only if the class is public. */
  14. class Ideone
  15. {
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. System.out.println( "Java vendor and version:" ) ;
  19. System.out.println( " " + System.getProperty("java.vendor") ) ;
  20. System.out.println( " " + Runtime.version() ) ;
  21. System.out.println( "" ) ;
  22.  
  23. // ---------- current moment ------------------
  24.  
  25. //ZoneOffset offset = ZoneId.of( "Africa/Casablanca" ).getRules().getOffset( Instant.now() ) ;
  26.  
  27. Instant instant = Instant.now() ;
  28. ZoneId z = ZoneId.of( "Africa/Casablanca" ) ;
  29. ZoneRules rules = z.getRules() ;
  30.  
  31. ZoneOffset offset = rules.getOffset( instant ) ;
  32. boolean isDst = rules.isDaylightSavings( instant ) ;
  33.  
  34. System.out.println( "offset.toString(): " + offset ) ;
  35. System.out.println( "isDst: " + isDst ) ;
  36.  
  37. // ---------- specific date ------------------
  38.  
  39. LocalDate localDate = LocalDate.parse( "2019-05-20" ) ;
  40. ZonedDateTime zdt = localDate.atStartOfDay( z ) ;
  41. System.out.println( "zdt.toString(): " + zdt ) ;
  42. System.out.println(
  43. "offset: " + rules.getOffset( zdt.toInstant() ) +
  44. " | is in DST: " + rules.isDaylightSavings( zdt.toInstant() )
  45. );
  46. }
  47. }
Success #stdin #stdout 0.19s 39724KB
stdin
Standard input is empty
stdout
Java vendor and version:
    Oracle Corporation
    12.0.1+12

offset.toString(): +01:00
isDst: false
zdt.toString(): 2019-05-20T00:00+01:00[Africa/Casablanca]
offset: +01:00  |  is in DST: false