// 获取当前日期
export const getDate = (separator) => {
let date = new Date()
let today = ''
let y = date.getFullYear(),
m =
date.getMonth() + 1 >= 10
? date.getMonth() + 1
: '0' + (date.getMonth() + 1),
d = date.getDate() >= 10 ? date.getDate() : '0' + date.getDate(),
hh = date.getHours() >= 10 ? date.getHours() : '0' + date.getHours(),
mm = date.getMinutes() >= 10 ? date.getMinutes() : '0' + date.getMinutes(),
ss = date.getSeconds() >= 10 ? date.getSeconds() : '0' + date.getSeconds()
if (separator) {
if (separator === 'zh') {
today = y + '年' + m + '月' + date.getDate() + '日'
} else if (separator === 'sfm') {
today = y + '-' + m + '-' + d + ' ' + hh + ':' + mm + ':' + ss
} else {
today = y + separator + m + separator + d
}
} else {
today = y + '-' + m + '-' + d
}
return {
today: today,
}
}
日期封装(年月日时分秒)
最新推荐文章于 2024-08-22 14:32:34 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)