You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
General-AI-Platform-Web-Client/mock/utils/mockMoment.ts

39 lines
1.2 KiB
TypeScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

export function generateRandomDateTimeByYear(year) {
// 生成随机月份1-12
const month = Math.floor(Math.random() * 12) + 1;
// 生成随机日期1-31
const day = Math.floor(Math.random() * 31) + 1;
// 生成随机小时0-23
const hour = Math.floor(Math.random() * 24);
// 生成随机分钟0-59
const minute = Math.floor(Math.random() * 60);
// 生成随机秒钟0-59
const second = Math.floor(Math.random() * 60);
// 返回随机日期和时间的字符串
return `${year}-${month < 10 ? "0" : ""}${month}-${
day < 10 ? "0" : ""
}${day} ${hour < 10 ? "0" : ""}${hour}:${minute < 10 ? "0" : ""}${minute}:${
second < 10 ? "0" : ""
}${second}`;
}
export function generateRandomMoment(date = new Date(), type = "HH:mm:ss") {
// 生成随机小时0-23
const hour = Math.floor(Math.random() * 24);
// 生成随机分钟0-59
const minute = Math.floor(Math.random() * 60);
// 生成随机秒钟0-59
const second = Math.floor(Math.random() * 60);
// 返回随机日期和时间的字符串
return `${hour < 10 ? "0" : ""}${hour}:${minute < 10 ? "0" : ""}${minute}:${
second < 10 ? "0" : ""
}${second}`;
}