时间戳转string string 转时间 获取时间


1、时间戳转时间

function formatDateDay(value,type='-') {
    if(value) {
let date = new Date(parseInt(value) * 1000)
let Y=date.getFullYear()
let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1)
let D = date.getDate()
let h = date.getHours()
let m = date.getMinutes()
D=parseInt(D)<10 ? '0'+D: D
h=parseInt(h)<10 ? '0'+h: h
m=parseInt(m)<10 ? '0'+m: m
return Y+type+M+type+D
}else{
return '暂无信息'
}
}

2、时间戳 时间差 是否显示时分

function getTimeDiff(value,timeT=0,needTime = false){

   let date = value===''?new Date():new Date(parseInt(value) * 1000)
date.setDate(date.getDate() + timeT);//如果有时间差
let Y = date.getFullYear()
let M = date.getMonth() + 1
let D = date.getDate()
let h = date.getHours()
let m = date.getMinutes()
M = parseInt(M) < 10 ? '0' + M : M
D = parseInt(D) < 10 ? '0' + D : D
h = parseInt(h) < 10 ? '0' + h : h
m = parseInt(m) < 10 ? '0' + m : m
if(needTime){
return Y + '-' + M + '-' + D + ' ' + h + ':' + m
} else {
return Y + '-' + M + '-' + D
}
}

3、时间转时间戳

function dateToTimestamp(date){
if(date){
date = date.replace(/\-/g, "/")
date = new Date(date).getTime()/1000
return date
}else{
return 0;
}
}
 
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM