MCPcopy Create free account
hub / github.com/Xu22Web/tech-study-js / formatDateTime

Function formatDateTime

tech-study.js:2369–2384  ·  view source on GitHub ↗

* @description 格式化日期时间 * @param time * @returns * @example * formatDateTime() -> "2022-09-01 08:00:00" * formatDateTime(new Date()) -> "2022-09-01 08:00:00" * formatDateTime(Date.now()) -> "2022-09-01 08:00:00"

(time = Date.now())

Source from the content-addressed store, hash-verified

2367 * formatDateTime(Date.now()) -> "2022-09-01 08:00:00"
2368 */
2369function formatDateTime(time = Date.now()) {
2370 const date = new Date(time);
2371 const s = date.getSeconds();
2372 const min = date.getMinutes();
2373 const h = date.getHours();
2374 const d = date.getDate();
2375 const m = date.getMonth() + 1;
2376 const y = date.getFullYear();
2377 // 日期
2378 const dateText = [y, m, d].map(formatDateNum).join('-');
2379 // 时间
2380 const timeText = [h, min, s].map(formatDateNum).join(':');
2381 // 日期时间
2382 const dateTimeText = `${dateText} ${timeText}`;
2383 return dateTimeText;
2384}
2385/**
2386 * @description 格式化时间
2387 * @param time

Callers 2

printColorFunction · 0.70
createModalFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected