1. 代碼java
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; private static Date getStartTime() { Calendar todayStart = Calendar.getInstance(); todayStart.set(Calendar.HOUR_OF_DAY, 0); todayStart.set(Calendar.MINUTE, 0); todayStart.set(Calendar.SECOND, 0); todayStart.set(Calendar.MILLISECOND, 0); return todayStart.getTime(); } private static Date getEndTime() { Calendar todayEnd = Calendar.getInstance(); todayEnd.set(Calendar.HOUR_OF_DAY, 23); todayEnd.set(Calendar.MINUTE, 59); todayEnd.set(Calendar.SECOND, 59); todayEnd.set(Calendar.MILLISECOND, 999); return todayEnd.getTime(); }
public static String getStartTimeStr(){
return new SimpleDateFormat(DATE_FORMAT).format(getStartTime());
}
public static String getEndTimeStr(){
return new SimpleDateFormat(DATE_FORMAT).format(getEndTime());
}
2. 其餘的joda框架好像也能夠方便get到當日起止時間戳框架
java自帶日期也好使, Calendar.HOUR_OF_DAY要搞對,否則出現過了12點,結果從今日12時到明日12時spa