Java DateTimeFormatter getStartOfDay(Date dateToFormat)

Here you can find the source of getStartOfDay(Date dateToFormat)

Description

Retuns the start of day in Date format.

License

Open Source License

Parameter

Parameter Description
dateToFormat Date to be formatted, cannot be null.

Return

Date limited to the end of day e.g. 00.00 of the this day

Declaration

public static Date getStartOfDay(Date dateToFormat) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;

public class Main {
    /**/*from w w w  . j  av  a 2 s  . co m*/
     * Retuns the start of day in Date format.
     * 
     * @param dateToFormat Date to be formatted, cannot be null.
     * @return Date limited to the end of day e.g. 00.00 of the this day
     */
    public static Date getStartOfDay(Date dateToFormat) {
        assert dateToFormat != null : "Date to be formatted should not be null";
        LocalDate date = dateToFormat.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        return Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant());
    }
}

Related

  1. getLocalizedDateFormat( final Locale LOCALE)
  2. getParsedTimeOrNull(String timeText, DateTimeFormatter formatForDisplayTime, DateTimeFormatter formatForMenuTimes, ArrayList formatsForParsing, Locale timePickerLocale)
  3. getPreferredDateFormat()
  4. getShortDateManualEntryFormatter()
  5. getShortFormatter(Locale locale)
  6. getTime(final String time, final DateTimeFormatter formatter)
  7. getTime(String format)
  8. getTimeFromEpochMilli(String value, boolean shortFormat, String errorText)
  9. getTimeStamp(final String dateTimeFormatPattern)