upload project source code
This commit is contained in:
57
后端源码/yifan.action-ai.cn/index/js/dateUtil.SHphbRyf.js
Normal file
57
后端源码/yifan.action-ai.cn/index/js/dateUtil.SHphbRyf.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import { aD as dayjs, ew as tryOnMounted, ex as tryOnUnmounted, al as toRefs, ak as reactive } from "./.pnpm.BW3P1y8f.js";
|
||||
const DATE_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
|
||||
function formatToDateTime(date, format = DATE_TIME_FORMAT) {
|
||||
return dayjs(date).format(format);
|
||||
}
|
||||
const useNow = (immediate = true) => {
|
||||
let timer;
|
||||
const state = reactive({
|
||||
year: 0,
|
||||
month: 0,
|
||||
week: "",
|
||||
day: 0,
|
||||
hour: "",
|
||||
minute: "",
|
||||
second: 0,
|
||||
meridiem: ""
|
||||
});
|
||||
const update = () => {
|
||||
const now = dayjs();
|
||||
const h = now.format("HH");
|
||||
const m = now.format("mm");
|
||||
const s = now.get("s");
|
||||
state.year = now.get("y");
|
||||
state.month = now.get("M") + 1;
|
||||
state.week = "星期" + ["日", "一", "二", "三", "四", "五", "六"][now.day()];
|
||||
state.day = now.get("date");
|
||||
state.hour = h;
|
||||
state.minute = m;
|
||||
state.second = s;
|
||||
state.meridiem = now.format("A");
|
||||
};
|
||||
function start() {
|
||||
update();
|
||||
clearInterval(timer);
|
||||
timer = setInterval(() => update(), 1e3);
|
||||
}
|
||||
function stop() {
|
||||
clearInterval(timer);
|
||||
}
|
||||
tryOnMounted(() => {
|
||||
if (immediate) {
|
||||
start();
|
||||
}
|
||||
});
|
||||
tryOnUnmounted(() => {
|
||||
stop();
|
||||
});
|
||||
return {
|
||||
...toRefs(state),
|
||||
start,
|
||||
stop
|
||||
};
|
||||
};
|
||||
export {
|
||||
formatToDateTime as f,
|
||||
useNow as u
|
||||
};
|
||||
Reference in New Issue
Block a user