fn_get_date
// fn_get_date
function fn_get_date(timestamp) {
timestamp = timestamp > 1e11 ? timestamp : timestamp * 1000
let date = new Date(timestamp)
let y = date.getFullYear()
let m = checkTime(date.getMonth() + 1)
let d = checkTime(date.getDate())
let h = checkTime(date.getHours())
let min = checkTime(date.getMinutes())
let s = checkTime(date.getSeconds())
let obj = {
y, m, d, h, min, s,
ymd: `${y}/${m}/${d}`,
hm: `${h}:${min}`,
hms: `${h}:${min}:${s}`,
}
return obj
}
// formatTime
function formatTime(timestamp, type) {
timestamp && timestamp.toString().length == 13 ? (timestamp = timestamp) : (timestamp = timestamp * 1000); //时间戳设置成13位数
var time = new Date(timestamp);
var y = time.getFullYear(),
m = time.getMonth() + 1 > 9 ? time.getMonth() + 1 : "0" + (time.getMonth() + 1),
d = time.getDate() > 9 ? time.getDate() : "0" + time.getDate(),
h = time.getHours() > 9 ? time.getHours() : "0" + time.getHours(),
min = time.getMinutes() > 9 ? time.getMinutes() : "0" + time.getMinutes(),
s = time.getSeconds() > 9 ? time.getSeconds() : "0" + time.getSeconds();
var t_obj = {
y: y,
m: m,
d: d,
h: h,
min: min,
s: s,
};
if (type == 1) {
return t_obj;
} else if (type == 2) {
if (parseInt(Number(d)) > 0) {
return "".concat(m, "-").concat(d, " ").concat(h, ":").concat(min);
} else {
return "00-00-00 00:00";
}
} else if (type == 3) {
return ""
.concat(y, "/")
.concat(m, "/")
.concat(d, " <br />")
.concat(h, ":")
.concat(min, ":")
.concat(s);
}
}