42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
|
|
export default function getDate() {
|
|||
|
|
// 获取当前日期
|
|||
|
|
let date = new Date();
|
|||
|
|
|
|||
|
|
// 获取当前月份
|
|||
|
|
let nowMonth = date.getMonth() + 1;
|
|||
|
|
|
|||
|
|
// 获取当前是几号
|
|||
|
|
let strDate = date.getDate();
|
|||
|
|
|
|||
|
|
// 添加分隔符“-”
|
|||
|
|
let separator = "-";
|
|||
|
|
|
|||
|
|
// 对月份进行处理,1-9月在前面添加一个“0”
|
|||
|
|
if (nowMonth >= 1 && nowMonth <= 9) {
|
|||
|
|
nowMonth = "0" + nowMonth;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 对月份进行处理,1-9号在前面添加一个“0”
|
|||
|
|
if (strDate >= 0 && strDate <= 9) {
|
|||
|
|
strDate = "0" + strDate;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 最后拼接字符串,得到一个格式为(yyyy-MM-dd)的日期
|
|||
|
|
// const nowDate = date.getFullYear() + separator + nowMonth + separator + strDate;
|
|||
|
|
const nowDate = date.getFullYear() + separator + nowMonth;
|
|||
|
|
// const theSecondDay = date.getFullYear() + separator + nowMonth + separator + (strDate + 1);
|
|||
|
|
// return { nowDate, theSecondDay }
|
|||
|
|
return nowDate;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export function getNowTime() {
|
|||
|
|
let dateTime
|
|||
|
|
let yy = new Date().getFullYear()
|
|||
|
|
let mm = new Date().getMonth() + 1
|
|||
|
|
let dd = new Date().getDate()
|
|||
|
|
let hh = new Date().getHours()
|
|||
|
|
let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes()
|
|||
|
|
let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds()
|
|||
|
|
dateTime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
|
|||
|
|
return dateTime
|
|||
|
|
}
|