Advertisement
cd62131

use java.time.Period

Dec 8th, 2018
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import java.time.LocalDate;
  2. import java.time.Period;
  3. public class Ch {
  4.   public static void main(String[] args) {
  5.     int a = 20200502; LocalDate la = lo(a); System.out.println(la);
  6.     int b = 20190401; LocalDate lb = lo(b); System.out.println(lb);
  7.     Period p = Period.between(lb, la);
  8.     System.out.println(p);
  9.     System.out.println(p.getYears());
  10.     System.out.println(p.getMonths());
  11.     System.out.println(p.getDays());
  12.     System.out.println(la.minusYears(1).minusMonths(1).minusDays(1));
  13.     System.out.println(la.minus(Period.parse("P1Y1M1D")));
  14.   }
  15.   private static LocalDate lo(int a) {
  16.     return LocalDate.of(a / 10000, (a % 10000) / 100, a % 100);
  17.   }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement