get Last Date Of Last Year - Java java.time

Java examples for java.time:Year

Description

get Last Date Of Last Year

Demo Code


//package com.java2s;
import java.time.*;

import java.time.temporal.TemporalAdjusters;
import java.util.Date;

public class Main {
    public static Date getLastDateOfLastYear() {
        return toDate(LocalDate.now().minusYears(1)
                .with(TemporalAdjusters.lastDayOfYear()));
    }/* ww w . j  a v a  2s .  c  o m*/

    public static Date toDate(LocalDate date) {
        Instant instant = date.atStartOfDay()
                .atZone(ZoneId.systemDefault()).toInstant();
        return Date.from(instant);
    }

    public static Date toDate(LocalDateTime date) {
        Instant instant = date.atZone(ZoneId.systemDefault()).toInstant();
        return Date.from(instant);
    }
}

Related Tutorials