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