import { getLunar } from 'chinese-lunar-calendar'
// 获取当前年月日 时分秒
export function toDate(type) {
let time = new Date();
let wk = time.getDay()
let weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
//年
let y = time.getFullYear();
// 月
let m = (time.getMonth() + 1 + "").padStart("2", "0");
// 日
let d = (time.getDate() + "").padStart("2", "0");
// 时
let hh = (time.getHours() + "").padStart("2", "0");
// 分
let mm = (time.getMinutes() + "").padStart("2", "0");
// 秒
let ss = (time.getSeconds() + "").padStart("2", "0");
let getLunarDay = getLunar(time.getFullYear(), time.getMonth() + 1, time.getDate())
if (type == "YYYY-MM-DD hh:mm:ss") {
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
} else if (type == "YYYY/MM/DD hh:dd:ss") {
return `${y}/${m}/${d} ${hh}:${mm}:${ss}`;
} else if (type == "YYYY-MM-DD") {
return `${y}-${m}-${d}`;
} else {
return [`${y}/${m}/${d}`, `${hh} : ${mm} : ${ss}`, weeks[wk],getLunarDay]
}
}
显示年月日 时分秒 星期几 农历
最新推荐文章于 2024-07-06 19:46:39 发布