java获取时间整点工具代码
/**获取上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); }
微信搜索“HUC思梦”关注我吧,关注有惊喜,不定时有免费资源分享!