修改方法

This commit is contained in:
lxd 2025-03-13 10:14:28 +08:00
parent 2da071a1f2
commit 910c201f0f

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.common.util.date;
import cn.hutool.core.date.LocalDateTimeUtil;
import java.security.SecureRandom;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
@ -149,9 +150,14 @@ public class DateUtils {
public static String generateUniqueCode() {
// 获取当前日期和时间
LocalDateTime now = LocalDateTime.now();
// 定义格式化模式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
// 定义格式化模式年月日 + + 毫秒
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddssSSS");
// 格式化当前日期和时间为字符串
return now.format(formatter);
String timestamp = now.format(formatter);
// 生成随机数
SecureRandom random = new SecureRandom();
int randomNumber = random.nextInt(100); // 生成 0 99 之间的随机数
// 结合时间戳和随机数生成唯一码
return timestamp + String.format("%02d", randomNumber);
}
}