get Last Date Of Last Quarter - Java java.time

Java examples for java.time:Quarter

Description

get Last Date Of Last Quarter

Demo Code


import java.time.*;
import java.time.temporal.IsoFields;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;

public class Main{
    public static Date getLastDateOfLastQuarter() {
        return toDate(LocalDate.now().with(
                new LastDateOfQuarterAdjuster(true)));
    }/*from   w  w w.  j av  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