工具类-时间优化
This commit is contained in:
@@ -200,15 +200,14 @@ public class AgentUtil {
|
||||
|
||||
public static long roundMinutes(){
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 四舍五入到最近的5分钟
|
||||
LocalDateTime roundedTime = now
|
||||
.truncatedTo(ChronoUnit.MINUTES) // 先去掉秒和纳秒
|
||||
.withMinute((int) (Math.round(now.getMinute() / 5.0) * 5))
|
||||
.withSecond(0)
|
||||
.withNano(0);
|
||||
// 处理分钟进位的情况
|
||||
if (roundedTime.getMinute() == 60) {
|
||||
roundedTime = roundedTime.plusHours(1).withMinute(0);
|
||||
int minute = now.getMinute();
|
||||
int roundedMinute = (int) (Math.round(minute / 5.0) * 5);
|
||||
|
||||
LocalDateTime roundedTime ;
|
||||
if (roundedMinute == 60) {
|
||||
roundedTime = now.plusHours(1).withMinute(0).withSecond(0).withNano(0);
|
||||
} else {
|
||||
roundedTime = now.withMinute(roundedMinute).withSecond(0).withNano(0);
|
||||
}
|
||||
// 转换为10位时间戳
|
||||
long timestamp = roundedTime.atZone(ZoneId.systemDefault()).toEpochSecond();
|
||||
|
||||
Reference in New Issue
Block a user