Files
senlan/utils/timeUtil/timeUtil.js
2025-04-23 19:50:30 +08:00

15 lines
810 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;