Java Day of getFirstOfDay(Date date)

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

Description

get First Of Day

License

Open Source License

Parameter

Parameter Description
date a parameter

Return

Date

Declaration

public static Date getFirstOfDay(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";

    /**/* ww w .jav  a  2 s .c o  m*/
     * @param date
     * @return Date
     */
    public static Date getFirstOfDay(Date date) {
        String dateString = new SimpleDateFormat(EARER_IN_THE_DAY).format(date);
        try {
            return new SimpleDateFormat(LONG_DATE_FORMAT_STR).parse(dateString);
        } catch (ParseException e) {
            return null;
        }
    }

    /**
     * @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;
    }

    /**
     * @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);
    }
}

Related

  1. getFirstDay(boolean isNeedHH24MISS)
  2. getFirstDay(boolean withTime)
  3. getFirstDay(Date date)
  4. getFirstDayInThisQuarter(String nowDate)
  5. getFirstDayOfQuarter(Date date)
  6. getFirstTimeInDay(Date day)
  7. getFormattedNowDatePlusDays(int days, String dateFormat)
  8. getFullAge(Date birthday)
  9. getIncrementDaysSecond(String strDate, int sec)