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.  
  15. Map < LocalDate, Set < ZonedDateTime > > map = new HashMap <>( );
  16. Set < ZonedDateTime > set = null;
  17.  
  18. ZoneId z = ZoneId.of( "Africa/Tunis" );
  19. LocalDate today = LocalDate.now( z );
  20. ZonedDateTime todayStart = today.atStartOfDay( z ); // Determine the first moment of the day in a particular time zone.
  21. map.putIfAbsent( todayStart.toLocalDate( ) , new HashSet <>( ) );
  22. set = map.get( todayStart.toLocalDate( ) ) ;
  23. set.add( todayStart );
  24.  
  25. ZonedDateTime zdt1 = todayStart.plusHours( 6 );
  26. map.putIfAbsent( zdt1.toLocalDate( ) , new HashSet <>( ) );
  27. set = map.get( zdt1.toLocalDate( ) ) ;
  28. set.add( zdt1 );
  29.  
  30. ZonedDateTime zdt2 = todayStart.plusDays( 2 );
  31. map.putIfAbsent( zdt2.toLocalDate( ) , new HashSet <>( ) );
  32. set = map.get( zdt2.toLocalDate( ) ) ;
  33. set.add( zdt2 );
  34.  
  35. ZonedDateTime zdt3 = todayStart.plusMonths( 4 );
  36. map.putIfAbsent( zdt3.toLocalDate( ) , new HashSet <>( ) );
  37. set = map.get( zdt3.toLocalDate( ) ) ;
  38. set.add( zdt3 );
  39.  
  40. System.out.println( "map.toString(): " + map );
  41.  
  42.  
  43. }
  44. }
Success #stdin #stdout 0.23s 34432KB
stdin
Standard input is empty
stdout
map.toString(): {2018-01-25=[2018-01-25T00:00+01:00[Africa/Tunis]], 2018-01-23=[2018-01-23T00:00+01:00[Africa/Tunis], 2018-01-23T06:00+01:00[Africa/Tunis]], 2018-05-23=[2018-05-23T00:00+01:00[Africa/Tunis]]}