/** * 獲取未來 第 past 天的日期 * * @param past * @return */ private static Date getFetureDate(int past) throws ParseException { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + past); Date today = calendar.getTime(); DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String str = format.format(today); Date d2 = format.parse(str); System.out.println(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); return resultDate; }
獲取第n天后的日期
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.