Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.time.LocalDate;
  2. import java.time.Period;
  3. import java.time.Month;
  4.  
  5.  
  6. public class Joulu {
  7.  
  8.     public static void main(String[] args) {
  9.        
  10.         LocalDate now = LocalDate.now();
  11.         //LocalDate now = LocalDate.of(2019, 12, 31);
  12.         //LocalDate now = LocalDate.of(2019, 12, 25);
  13.         //LocalDate now = LocalDate.of(2019, 12, 24);
  14.        
  15.         int currentYear = now.getYear();
  16.         LocalDate christmasDate = LocalDate.of(currentYear, 12, 24);
  17.         LocalDate newYear = LocalDate.of(currentYear, 12, 31);
  18.        
  19.         if(now.getDayOfYear() > christmasDate.getDayOfYear()
  20.             && now.getDayOfYear() <= newYear.getDayOfYear()) {
  21.             christmasDate = christmasDate.withYear(currentYear + 1);
  22.         }
  23.        
  24.         Period timeLeftUntilChristmas = now.until(christmasDate);
  25.        
  26.         if(timeLeftUntilChristmas.isZero()) {
  27.             System.out.println("ON JOULUAATTO!");
  28.         } else {
  29.              System.out.println("Jouluaattoon on aikaa " + timeLeftUntilChristmas.getMonths() + " kuukautta ja " + timeLeftUntilChristmas.getDays() + " päivää");
  30.         }
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement