Android examples for java.util:Day
get First Time Of Day
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static final String dateFormatYMDHMS = "yyyy-MM-dd HH:mm:ss"; public static final String dateFormatYMD = "yyyy-MM-dd"; public static long getFirstTimeOfDay() { Date date = null;//from ww w. j ava 2 s. c o m try { String currentDate = getCurrentDate(dateFormatYMD); date = getDateByFormat(currentDate + " 00:00:00", dateFormatYMDHMS); return date.getTime(); } catch (Exception e) { } return -1; } public static String getCurrentDate(String format) { String curDateTime = null; try { SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat( format); Calendar c = new GregorianCalendar(); curDateTime = mSimpleDateFormat.format(c.getTime()); } catch (Exception e) { e.printStackTrace(); } return curDateTime; } public static Date getDateByFormat(String strDate, String format) { SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format); Date date = null; try { date = mSimpleDateFormat.parse(strDate); } catch (ParseException e) { e.printStackTrace(); } return date; } }