Here you can find the source of getFirstOfDay(Date date)
Parameter | Description |
---|---|
date | a parameter |
public static Date getFirstOfDay(Date date)
//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); } }