Java Day of getBeginOfDay(Date date)

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

Description

get Begin Of Day

License

Open Source License

Parameter

Parameter Description
date a parameter

Return

Date

Declaration

public static Date getBeginOfDay(Date date) 

Method Source Code


//package com.java2s;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String LONG_DATE_FORMAT_STR = "yyyy-MM-dd HH:mm:ss";
    public static final String EARER_IN_THE_DAY = "yyyy-MM-dd 00:00:00.000";

    /**// w  ww .j av  a 2s .  c o  m
     * @param date
     * @return Date
     */
    public static Date getBeginOfDay(Date date) {
        String beginDay = new SimpleDateFormat(EARER_IN_THE_DAY).format(date);
        try {
            return parserStringToDate(beginDay, LONG_DATE_FORMAT_STR);
        } catch (ParseException e) {
        }
        return null;
    }

    /**
     * @param dateString
     * @param format
     * @return Date
     * @throws ParseException
     */
    public static Date parserStringToDate(String dateString, String format) throws ParseException {
        DateFormat dateFormat = new SimpleDateFormat(format);
        return dateFormat.parse(dateString);
    }

    /**
     * @param dateString
     * @param format
     * @return Date
     */
    public static Date parse(String dateString, String format) {
        Date date = null;
        try {
            date = parserStringToDate(dateString, format);
        } catch (Exception e) {
        }
        return date;
    }
}

Related

  1. getAgeOfCalendar(String birthDayString)
  2. getApisPaxBirthday(String dob)
  3. getBeforeDate(int day)
  4. getBeforeOrAfterDay(Date date, String format, Integer days)
  5. getBeginEndTimeOfDay(Date day)
  6. getBeginTimeOfDay(Date date, int offset)
  7. getBirthday(String age)
  8. getBirthDay(String idCard)
  9. getBirthDayDateFormat()