java獲取時間整點工具代碼
阿新 • • 發佈:2018-06-22
time IV calendar 代碼 pan ins sdf 獲取時間 ring
/**獲取上n個小時整點小時時間 * @param date * @return */ public static String getLastHourTime(Date date,int n){ Calendar ca = Calendar.getInstance(); ca.set(Calendar.MINUTE, 0); ca.set(Calendar.SECOND, 0); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); ca.set(Calendar.HOUR_OF_DAY, ca.get(Calendar.HOUR_OF_DAY)-n); date = ca.getTime(); return sdf.format(date); } /**獲取當前時間的整點小時時間 * @param date * @return */ public static String getCurrHourTime(Date date){ Calendar ca = Calendar.getInstance(); ca.set(Calendar.MINUTE, 0); ca.set(Calendar.SECOND,0); date = ca.getTime(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); return sdf.format(date); }
java獲取時間整點工具代碼