fork 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.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. LocalDate x = LocalDate.of( 2021 , Month.MARCH , 27 ) ;
  15.  
  16. ZoneId zoneId = ZoneId.of( "Africa/Casablanca" ) ;
  17. ZonedDateTime zdt = ZonedDateTime.now( zoneId ) ;
  18. LocalDate y = LocalDate.from( zdt ) ;
  19. LocalDate z = zdt.toLocalDate() ;
  20.  
  21. System.out.println( "x.toString(): " + x ) ;
  22. System.out.println( "y.toString(): " + y ) ;
  23. System.out.println( "z.toString(): " + z ) ;
  24. }
  25. }
Success #stdin #stdout 0.15s 53624KB
stdin
Standard input is empty
stdout
x.toString(): 2021-03-27
y.toString(): 2021-05-25
z.toString(): 2021-05-25