get First Date Of Current Quarter - Java java.time

Java examples for java.time:Quarter

Description

get First Date Of Current 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 getFirstDateOfCurrentQuarter() {
        return toDate(LocalDate.now().with(
                new FirstDateOfQuarterAdjuster(false)));
    }//from   www. j a  v a  2  s  .  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