Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

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

    public static List<LocalDate> getDatesFrom(Date startDate) {
        List<LocalDate> dates = new ArrayList<>();

        LocalDate startLocalDate = getLocalDateFromDate(startDate);

        LocalDate endLocalDate = LocalDate.now();

        dates.add(startLocalDate);
        for (int i = 0; i < ChronoUnit.DAYS.between(startLocalDate, endLocalDate); i++) {
            dates.add(startLocalDate.plusDays(i + 1));
        }

        return dates;
    }

    public static LocalDate getLocalDateFromDate(Date date) {
        return LocalDateTime.ofInstant(new Date(date.getTime()).toInstant(), ZoneId.systemDefault()).toLocalDate();
    }
}