get First Date Of Last Quarter - Java java.time

Java examples for java.time:Quarter

Description

get First 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 getFirstDateOfLastQuarter() {
        return toDate(LocalDate.now().with(
                new FirstDateOfQuarterAdjuster(true)));
    }//from   w  ww .jav  a2s. 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