start Of Day In Default Zone - Java java.time

Java examples for java.time:Timezone

Description

start Of Day In Default Zone

Demo Code


//package com.java2s;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneId;
import java.util.Date;

public class Main {
    public static Date startOfDayInDefaultZone(LocalDate localDate) {
        return Date.from(localDate.atStartOfDay(ZoneId.systemDefault())
                .toInstant());/*  ww w  .  j  a  va  2 s . c o m*/
    }

    public static Date startOfDayInDefaultZone(int year, Month month,
            int dayOfMonth) {
        return dateWithTimeInDefaultZone(year, month, dayOfMonth, 0, 0);
    }

    public static Date dateWithTimeInDefaultZone(int year, Month month,
            int dayOfMonth, int hour, int minute) {
        LocalDateTime ldt = LocalDateTime.of(year, month, dayOfMonth, hour,
                minute);
        return Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
    }
}

Related Tutorials