first commit
This commit is contained in:
16
utils/date.ts
Normal file
16
utils/date.ts
Normal file
@ -0,0 +1,16 @@
|
||||
export function formatDateTime() {
|
||||
const now = new Date();
|
||||
|
||||
// 获取年份、月份、日期、小时、分钟、秒数
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要加1
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const hours = String(now.getHours()).padStart(2, '0');
|
||||
const minutes = String(now.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(now.getSeconds()).padStart(2, '0');
|
||||
|
||||
// 拼接成需要的格式
|
||||
const formattedDateTime = `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`;
|
||||
|
||||
return formattedDateTime;
|
||||
}
|
Reference in New Issue
Block a user