Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.time.LocalDate;
- import java.time.Period;
- import java.time.Month;
- public class Joulu {
- public static void main(String[] args) {
- LocalDate now = LocalDate.now();
- //LocalDate now = LocalDate.of(2019, 12, 31);
- //LocalDate now = LocalDate.of(2019, 12, 25);
- //LocalDate now = LocalDate.of(2019, 12, 24);
- int currentYear = now.getYear();
- LocalDate christmasDate = LocalDate.of(currentYear, 12, 24);
- LocalDate newYear = LocalDate.of(currentYear, 12, 31);
- if(now.getDayOfYear() > christmasDate.getDayOfYear()
- && now.getDayOfYear() <= newYear.getDayOfYear()) {
- christmasDate = christmasDate.withYear(currentYear + 1);
- }
- Period timeLeftUntilChristmas = now.until(christmasDate);
- if(timeLeftUntilChristmas.isZero()) {
- System.out.println("ON JOULUAATTO!");
- } else {
- System.out.println("Jouluaattoon on aikaa " + timeLeftUntilChristmas.getMonths() + " kuukautta ja " + timeLeftUntilChristmas.getDays() + " päivää");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement