1234567891011121314151617181920212223242526 |
- const formatTime = (time, type) => {
- var date = new Date(time);
- var format = type || "YYYY-MM-DD HH:NN:SS";
- const year = date.getFullYear();
- const month =
- date.getMonth() + 1 < 10
- ? "0" + (date.getMonth() + 1)
- : date.getMonth() + 1;
- const day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
- const hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
- const minute =
- date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
- const second =
- date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
- format.indexOf("YYYY") > -1 ? (format = format.replace("YYYY", year)) : "";
- format.indexOf("MM") > -1 ? (format = format.replace("MM", month)) : "";
- format.indexOf("DD") > -1 ? (format = format.replace("DD", day)) : "";
- format.indexOf("HH") > -1 ? (format = format.replace("HH", hour)) : "";
- format.indexOf("NN") > -1 ? (format = format.replace("NN", minute)) : "";
- format.indexOf("SS") > -1 ? (format = format.replace("SS", second)) : "";
- return format;
- }
- module.exports = {
- formatTime
- }
|