Java tutorial
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static long getTodayStartMillis() { // String dateStr = millisToStringDate(System.currentTimeMillis(), "yyyy-MM-dd"); // return string2Millis(dateStr, "yyyy-MM-dd"); return getOneDayStartMillis(System.currentTimeMillis()); } public static long getOneDayStartMillis(long millis) { String dateStr = millisToStringDate(millis, "yyyy-MM-dd"); return string2Millis(dateStr, "yyyy-MM-dd"); } public static String millisToStringDate(long millis) { return millisToStringDate(millis, "yyyy-MM-dd HH:mm:ss"); } public static String millisToStringDate(long millis, String pattern) { SimpleDateFormat format = new SimpleDateFormat(pattern); return format.format(new Date(millis)); } public static long string2Millis(String str, String pattern) { SimpleDateFormat format = new SimpleDateFormat(pattern); long millis = 0; try { millis = format.parse(str).getTime(); } catch (ParseException e) { } return millis; } }