get Start Of Day from java.util.Date via Instant - Java java.time

Java examples for java.time:Instant

Description

get Start Of Day from java.util.Date via Instant

Demo Code


//package com.java2s;

import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Date;

public class Main {
    public static Date getStartOfDay(Date date) {
        if (date == null) {
            return null;
        }/*from   w w  w .  ja v  a  2s.  c o m*/
        return Date.from(date.toInstant().atZone(ZoneId.systemDefault())
                .truncatedTo(ChronoUnit.DAYS).toInstant());
    }
}

Related Tutorials