hutool获取当前时间前后分钟的方法


/**
* 当前时间的前1分钟的时间
* 结果:newDate = 2020-12-24 13:45:40 Before=2020-12-24 13:44:40
*
* @param now
* @return
*/
public static String getOneMinutebeforeTime(String now) {
Date date = DateUtil.parse(now);
Date newDate = DateUtil.offset(date, DateField.MINUTE, -1);
String startTime = DateUtil.format(newDate, "yyyy-MM-dd HH:mm:ss");
return startTime;
}
/**
* 当前时间的后1个分钟的时间
* 结果:newDate = 2020-12-24 13:45:40 Before=2020-12-24 13:46:40
*
* @param now
* @return
*/
public static String getOneMinuteAfterTime(String now) {
Date date = DateUtil.parse(now);
Date newDate = DateUtil.offset(date, DateField.MINUTE, 1);
String startTime = DateUtil.format(newDate, "yyyy-MM-dd HH:mm:ss");
return startTime;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM