List of usage examples for java.time LocalDate withYear
public LocalDate withYear(int year)
From source file:Main.java
public static void main(String[] args) { LocalDate a = LocalDate.of(2014, 6, 30); LocalDate b = a.withYear(2015); System.out.println(b);//from w ww. ja va 2s.co m }
From source file:Main.java
public static void main(String[] args) { Period p = Period.between(LocalDate.of(2009, Month.JANUARY, 21), LocalDate.of(2019, Month.JANUARY, 21)); System.out.println(p.get(ChronoUnit.DAYS)); LocalDate today = LocalDate.now(); LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1); LocalDate nextBDay = birthday.withYear(today.getYear()); nextBDay = nextBDay.plusYears(1);/*from w w w . ja v a 2 s .c o m*/ p = Period.between(today, nextBDay); long p2 = ChronoUnit.DAYS.between(today, nextBDay); System.out.println(p.getMonths() + " months"); System.out.println(p.getDays() + " days"); }
From source file:Main.java
public static void main(String[] args) { LocalDate localDate1 = LocalDate.of(2014, Month.MAY, 2); System.out.println(localDate1); LocalDate localDate2 = localDate1.withYear(2015); System.out.println(localDate2); LocalDate localDate3 = localDate1.withYear(2014).withMonth(7); System.out.println(localDate3); }
From source file:Main.java
public static void main(String[] args) { LocalDate today = LocalDate.now(); LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1); LocalDate nextBDay = birthday.withYear(today.getYear()); //If your birthday has occurred this year already, add 1 to the year. if (nextBDay.isBefore(today) || nextBDay.isEqual(today)) { nextBDay = nextBDay.plusYears(1); }/*from w w w . j ava2 s . co m*/ Period p = Period.between(today, nextBDay); long p2 = ChronoUnit.DAYS.between(today, nextBDay); System.out.println("There are " + p.getMonths() + " months, and " + p.getDays() + " days until your next birthday. (" + p2 + " total)"); }
From source file:Main.java
public static void main(String[] argv) { LocalDate today = LocalDate.now(); if (today.isLeapYear()) { System.out.println("This year is Leap year"); } else {/*www . j ava 2 s . c o m*/ System.out.println("not a Leap year"); } if (today.withYear(2016).isLeapYear()) { System.out.println("2016 is Leap year"); } }