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

时间:2021-04-06 12:42:30   收藏:0   阅读:436
/**
* 当前时间的前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;
}

原文:https://www.cnblogs.com/zysnba/p/14620246.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!