// 获取当前日期,格式 yyyy-MM-dd
export function date() {
return new Date().toJSON().split("T")[0];
}
// 获取当前时间,格式 hh:mm:ss
export function dateTime() {
return new Date().toTimeString().split(" ")[0];
}
/**
* @description: 获取当前时间,格式为yyyy-MM-dd hh:mm:ss
* @return {string} 当前时间
*/
export function timeNow() {
let date = new Date();
// 调整日期格式
let options = {
hour12: false,
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit"
};
// 将日期格式中的“/”转成“-”
return date.toLocaleString("zh", options).replace(/\//g, "-");
}