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. import java.time.*;
  7. import java.time.temporal.*;
  8. import java.time.format.*;
  9.  
  10.  
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Ideone
  13. {
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16. ZoneId z = ZoneId.of( "America/Montreal" );
  17. LocalDate today = LocalDate.now( z );
  18. DayOfWeek dow = today.getDayOfWeek();
  19.  
  20. Set<DayOfWeek> weekend = EnumSet.of( DayOfWeek.SATURDAY , DayOfWeek.SUNDAY );
  21.  
  22. Boolean todayIsWeekend = weekend.contains( dow );
  23. DayOfWeek firstDayOfWeek = DayOfWeek.MONDAY ;
  24. LocalDate startOfWeek = null ;
  25. if( todayIsWeekend ) {
  26. startOfWeek = today.with( TemporalAdjusters.next( firstDayOfWeek ) );
  27. } else {
  28. startOfWeek = today.with( TemporalAdjusters.previousOrSame( firstDayOfWeek ) );
  29. }
  30.  
  31. // Print report.
  32. System.out.println( "Today: " + today );
  33. LocalDate ld = startOfWeek ;
  34. int countDaysToPrint = ( DayOfWeek.values().length - weekend.size() );
  35. for( int i = 1 ; i <= countDaysToPrint ; i++ ) {
  36. String dayName = ld.getDayOfWeek().getDisplayName( TextStyle.FULL , Locale.CANADA_FRENCH ) ;
  37. System.out.println( ld + " " + dayName );
  38. // Set up the next loop.
  39. ld = ld.plusDays( 1 );
  40. }
  41. }
  42. }
Success #stdin #stdout #stderr 0.11s 712192KB
stdin
Standard input is empty
stdout
Today: 2016-11-26
2016-11-28 lundi
2016-11-29 mardi
2016-11-30 mercredi
2016-12-01 jeudi
2016-12-02 vendredi
stderr
Java HotSpot(TM) Client VM warning: No monotonic clock was available - timed services may be adversely affected if the time-of-day clock changes