Java Date Start getStartTimeOfDay(Date date)

Here you can find the source of getStartTimeOfDay(Date date)

Description

 Start time of the given date, specific to the second. 

License

Open Source License

Parameter

Parameter Description
date target date

Return

Date

Declaration

public static Date getStartTimeOfDay(Date date) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    /**//from   w w  w  . j  a va2  s .  c  om
     * <pre>
     * Start time of the given date, specific to the second. 
     * Example: The date is 2011-12-09 The last time 2011-12-09 00:00:00.000
     * </pre>
     * 
     * <pre>
     * DateUtils.getStartTimeOfDay(2011-12-09) = 2011-12-09 00:00:00.000
     * </pre>
     * 
     * @param date target date
     * @return Date
     */
    public static Date getStartTimeOfDay(Date date) {
        Date result = null;
        if (date != null) {
            Calendar calendar = getCalendar(date);
            int year = calendar.get(Calendar.YEAR);
            int month = calendar.get(Calendar.MONTH);
            int day = calendar.get(Calendar.DATE);
            calendar.set(year, month, day, 0, 0, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            result = calendar.getTime();
        }
        return result;
    }

    /**
     * get GregorianCalendar.
     * 
     * @return Calendar,GregorianCalendar.
     */
    public static Calendar getCalendar() {
        return new GregorianCalendar();
    }

    /**
     * get GregorianCalendar with given date.
     * 
     * @param date Date.
     * @return Calendar, GregorianCalendar.
     */
    public static Calendar getCalendar(Date date) {
        Calendar calendar = getCalendar();
        calendar.setTime(date);
        return calendar;
    }
}

Related

  1. getStartOfMonth(Date dt)
  2. getStartOfMonth(Date dt)
  3. getStartOfQuarter(Date dt)
  4. getStartTimeByManDay(Date serviceStartTime)
  5. getStartTimeOfDate(Date date)
  6. getStartTimeOfDay(Date date)
  7. getStrDateToDate(String dateStr)
  8. getStringDate()
  9. getStringDate(byte[] block, int pos)