Get the first timestamp in this day. - Java java.time

Java examples for java.time:Day

Description

Get the first timestamp in this day.

Demo Code


//package com.java2s;

import java.time.*;

public class Main {
    /**//from   w  w w  . j  a  v a 2  s  . c o  m
     * Get the first timestamp in this day.
     * 
     * @param timestamp
     * @return
     */
    public static long getDayHeadMills(long timestamp) {
        Instant instant = Instant.ofEpochMilli(timestamp);
        ZonedDateTime dateTime = ZonedDateTime.ofInstant(instant,
                ZoneId.systemDefault());

        ZonedDateTime dateHead = ZonedDateTime.of(dateTime.getYear(),
                dateTime.getMonthValue(), dateTime.getDayOfMonth(), 0, 0,
                0, 0, ZoneId.systemDefault());
        return dateHead.toInstant().toEpochMilli();
    }
}

Related Tutorials