UNPKG

821 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.dynamicFormatDateTime = void 0;
4function fillZero(digit) {
5 if (Math.abs(digit) > 10)
6 return String(digit);
7 return digit.toString().padStart(2, '0');
8}
9function dynamicFormatDateTime(date) {
10 const year = date.getFullYear();
11 const month = fillZero(date.getMonth() + 1);
12 const day = fillZero(date.getDate());
13 const yyyyMMDD = `${year}-${month}-${day}`;
14 const hour = date.getHours();
15 const minutes = date.getMinutes();
16 const seconds = date.getSeconds();
17 if (hour || minutes || seconds)
18 return `${yyyyMMDD} ${fillZero(hour)}:${fillZero(minutes)}:${fillZero(seconds)}`;
19 return yyyyMMDD;
20}
21exports.dynamicFormatDateTime = dynamicFormatDateTime;
22//# sourceMappingURL=dateFormat.js.map
\No newline at end of file