15 lines
810 B
JavaScript
15 lines
810 B
JavaScript
const getNowTime = function() {
|
||
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'); // 获取当前小时(0-23),并确保是两位数
|
||
const minutes = String(now.getMinutes()).padStart(2, '0'); // 获取当前分钟,并确保是两位数
|
||
const seconds = String(now.getSeconds()).padStart(2, '0'); // 获取当前秒数,并确保是两位数
|
||
|
||
// 拼接字符串并返回
|
||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||
}
|
||
|
||
|
||
module.exports = getNowTime; |