时间戳转时间格式
function timestamp_time(timestamp){
if (timestamp > 9999999999) {
// 接受参数为 timestamp 时间戳
let time = timestamp
let timec = new Date(Number(time))//时间串
let year,month,day, hour, minute, second;
year = timec.getFullYear()
month = timec.getMonth()+1 < 10 ? “0”+ (timec.getMonth() + 1):timec.getMonth() + 1
day = timec.getDate() < 10 ? “0”+ timec.getDate():timec.getDate()
hour = timec.getHours() < 10 ? “0”+ timec.getHours():timec.getHours()
minute = timec.getMinutes() < 10 ? “0”+ timec.getMinutes():timec.getMinutes()
second = timec.getSeconds() < 10 ? “0”+ timec.getSeconds():timec.getSeconds()
return String(year)+"-"+String(month)+"-"+String(day) + " " + String(hour)+ “:” +String(minute)+ “:” +String(second)
} else {
// 接受参数为 timestamp 时间戳
let time = timestamp*1000
let timec = new Date(Number(time))//时间串
let year,month,day, hour, minute, second;
year = timec.getFullYear()
month = timec.getMonth()+1 < 10 ? “0”+ (timec.getMonth() + 1):timec.getMonth() + 1
day = timec.getDate() < 10 ? “0”+ timec.getDate():timec.getDate()
hour = timec.getHours() < 10 ? “0”+ timec.getHours():timec.getHours()
minute = timec.getMinutes() < 10 ? “0”+ timec.getMinutes():timec.getMinutes()
second = timec.getSeconds() < 10 ? “0”+ timec.getSeconds():timec.getSeconds()
return String(year)+"-"+String(month)+"-"+String(day) + " " + String(hour)+ “:” +String(minute)+ “:” +String(second)
}
}
时区时间转时间格式
function timezone_time(timestamp){
// 接受参数为 timestamp 时间戳
let time = new Date(timestamp).getTime()
let timec = new Date(Number(time))//时间串
let year,month,day, hour, minute, second;
year = timec.getFullYear()
month = timec.getMonth()+1 < 10 ? “0”+ (timec.getMonth() + 1):timec.getMonth() + 1
day = timec.getDate() < 10 ? “0”+ timec.getDate():timec.getDate()
hour = timec.getHours() < 10 ? “0”+ timec.getHours():timec.getHours()
minute = timec.getMinutes() < 10 ? “0”+ timec.getMinutes():timec.getMinutes()
second = timec.getSeconds() < 10 ? “0”+ timec.getSeconds():timec.getSeconds()
return String(year)+"-"+String(month)+"-"+String(day) + " " + String(hour)+ “:” +String(minute)+ “:” +String(second)
}
05-13
6344
04-13
1万+
10-13
1162