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. import java.time.temporal.*;
  9. import java.time.format.*;
  10.  
  11.  
  12. /* Name of the class has to be "Main" only if the class is public. */
  13. class Ideone
  14. {
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17.  
  18. ZoneId z = ZoneId.of( "Africa/Casablanca" ) ;
  19. LocalDate today = LocalDate.now( z ) ;
  20.  
  21. YearMonth ym = YearMonth.from( today ) ;
  22.  
  23. LocalDate firstOfNextMonth = ym.plusMonths( 1 ).atDay( 1 ) ;
  24.  
  25. long days = ChronoUnit.DAYS.between( today , firstOfNextMonth ) ;
  26. System.out.println( days + " days between " + today + " and " + firstOfNextMonth ) ;
  27.  
  28. Period p = Period.between( today , firstOfNextMonth ) ;
  29.  
  30.  
  31. }
  32. }
Success #stdin #stdout 0.15s 4386816KB
stdin
Standard input is empty
stdout
30 days between 2017-11-01 and 2017-12-01