獲取一天中的起始時間與結束時間


DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d = new Date();
String str = format.format(d);
System.out.println(d);
Date d2 = format.parse(str);

System.out.println(format2.format(d2));

int dayMis = 1000 * 60 * 60 * 24;// 一天的毫秒-1
// 返回自 1970 年 1 月 1 日 00:00:00 GMT 以來此 Date 對象表示的毫秒數。
long curMillisecond = d2.getTime();// 當天的毫秒
long resultMis = curMillisecond + (dayMis - 1); // 當天最后一秒
// 得到我須要的時間 當天最后一秒
Date resultDate = new Date(resultMis);
System.out.println(format2.format(resultDate));


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM