当前位置: 首页 > Web前端 > HTML

js时间戳转日期

时间:2023-04-02 20:06:52 HTML

/***时间戳转日期*@paramtimestamp*@returns{*}*/functiontimestampToTime(timestamp){vardate=newDate(timestamp*1000);//time如果stamp为10位,*1000为必填,如果时间戳为13位,则不需要乘以1000Y=date.getFullYear()+'-';M=(date.getMonth()+1<10?'0'+(date.getMonth()+1):date.getMonth()+1)+'-';D=date.getDate()+'';h=date.getHours()+':';m=date.getMinutes()+':';s=date.getSeconds();返回Y+M+D+h+m+s;}