森蓝小程序
This commit is contained in:
15
utils/timeUtil/timeUtil.js
Normal file
15
utils/timeUtil/timeUtil.js
Normal file
@@ -0,0 +1,15 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user