/**获取上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); }
原文地址:https://www.cnblogs.com/lm970585581/p/9212237.html
时间: 2024-11-07 09:21:38