Java LocalDate Between daysBetween(LocalDate date1, LocalDate date2)

Here you can find the source of daysBetween(LocalDate date1, LocalDate date2)

Description

days Between

License

Open Source License

Declaration

public static int daysBetween(LocalDate date1, LocalDate date2) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.time.*;

import java.util.Date;

public class Main {
    public static final ZoneId chinaZone = ZoneId.systemDefault();

    public static int daysBetween(LocalDate date1, LocalDate date2) {
        Period period = Period.between(date1, date2);
        return period.getDays();
    }/*from ww w.  java  2s  . c  o m*/

    public static int daysBetween(Date date1, Date date2) {
        Instant instantDate1 = date1.toInstant();
        Instant instantDate2 = date2.toInstant();
        LocalDate localDate1 = instantDate1.atZone(chinaZone).toLocalDate();
        LocalDate localDate2 = instantDate2.atZone(chinaZone).toLocalDate();
        instantDate1.atZone(chinaZone);
        Period period = Period.between(localDate1, localDate2);
        return period.getDays();
    }
}

Related

  1. daysBetween(LocalDate firstDate, LocalDate secondDate)
  2. getLocalDatesBetween(final LocalDate localDate1, final LocalDate localDate2)
  3. getRandomLocalDateBetween(int startYear, int endYear)
  4. isBetween(LocalDate date, LocalDate before, LocalDate after)