Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.time.LocalDate;
import java.time.Month;
import java.time.Period;
import java.time.temporal.ChronoUnit;

public class Main {
    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);

        p = Period.between(today, nextBDay);
        long p2 = ChronoUnit.DAYS.between(today, nextBDay);
        System.out.println(p.getMonths() + " months");
        System.out.println(p.getDays() + " days");
    }
}