m2pool_backend_app/public/times.js

52 lines
1.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class Times {
static bjTime(dateForm) {
if (dateForm === "") {
//解决deteForm为空传1970-01-01 00:00:00
return "";
} else {
var dateee = new Date(dateForm).toJSON();
var date = new Date(+new Date(dateee) + 8 * 3600 * 1000)
.toISOString()
.replace(/T/g, " ")
.replace(/\.[\d]{3}Z/, "");
return date;
}
}
static utcTime(dateForm) {
if (dateForm === "") {
//解决deteForm为空传1970-01-01 00:00:00
return "";
} else {
var dateee = new Date(dateForm).toJSON();
var date = new Date(+new Date(dateee))
.toISOString()
.replace(/T/g, " ")
.replace(/\.[\d]{3}Z/, "");
return date;
}
}
static times() {
const date = new Date();
const y = date.getFullYear();
const M = String(date.getMonth() + 1).padStart(2, '0');
const d = String(date.getDate()).padStart(2, '0');
const h = String(date.getHours()).padStart(2, '0');
const m = String(date.getMinutes()).padStart(2, '0');
const s = String(date.getSeconds()).padStart(2, '0');
return [
`${y}-${M}-${d} ${h}:${m}`, // 格式YYYY-MM-DD HH:mm
`${y}-${M}-${d} ${h}:${m}:${s}`, // 格式YYYY-MM-DD HH:mm:ss
`${y}-${M}-${d}`, // 格式YYYY-MM-DD
`${m}`, // 分钟格式mm
`${h}`, // 小时格式HH
`${d}` // 日期格式DD
];
}
}
module.exports = Times;