Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class Main {
    public static void main(String[] argv) {
        System.out.println(getDatesInPeriod(new Date(1422312311223L), new Date(1462312311223L)));
    }

    public static List<LocalDate> getDatesInPeriod(Date startDate, Date endDate) {
        List<LocalDate> dates = new ArrayList<>();
        LocalDate start = toLocalDate(startDate);
        LocalDate end = toLocalDate(endDate);
        while (!start.equals(end)) {
            dates.add(start);
            start = start.plusDays(1);
        }
        return dates;
    }

    public static LocalDate toLocalDate(Date date) {
        Date lDate = new Date(date.getTime());
        return lDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    }
}