时间戳问题

1.年月转化为时间戳(13位java)

let d = new Date('2019-02');
console.log(d.getTime(d)); //1548979200000

2.13位(java)

  11位(php、c++)一般需要除以1000取整

3.ant design中日期转为具体时间转化封装:

const changTimeT = (data) => {
if(!data) {
return "";
}

const date = new Date(data);

let yyyy = `${date.getFullYear()}`;
let mm = `${date.getMonth() + 1 > 9 ? date.getMonth() + 1 : '0'+(date.getMonth() + 1)}`;
let dd = `${date.getDate() > 9 ? date.getDate() : '0' + date.getDate()}`;

let hh = `${date.getHours() > 9 ? date.getHours() : '0' + date.getHours()}`;
let min = `${date.getMinutes() > 9 ? date.getMinutes() : '0' + date.getMinutes()}`;
let ss = `${date.getSeconds() > 9 ? date.getSeconds() : '0' + date.getSeconds()}`;

return {
'YYMMDD':`${yyyy}-${mm}-${dd}`,
'YYMMDD:HHMM':`${yyyy}-${mm}-${dd} ${hh}:${min}`,
"HHMMSS":`${hh}:${min}:${ss}`,
"YYMMDD:HHMMSS":`${yyyy}-${mm}-${dd} ${hh}:${min}:${ss}`
}
};
 
使用:import {changTimeT} ../../publicMethod
console.log("test-time",changTimeT(psTimeStart).YYMMDD)
 
************时间戳转为日期***************
timestampToTime(type,timestamp){
if(!timestamp){
return ''
}
let date = new Date(timestamp);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
let Y = date.getFullYear() + '-';
let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
let D = date.getDate()<10?'0'+date.getDate()+' ':date.getDate() + ' ';
let h = date.getHours()<10?'0'+date.getHours()+':':date.getHours() + ':';
let m = date.getMinutes()<10?'0'+date.getMinutes()+':':date.getMinutes() + ':';
let s = date.getSeconds()<10?'0'+date.getSeconds():date.getSeconds();
if(type==1){
return Y+M+D;
}else if(type==2){
return Y+M+D+h+m+s;
}else{
return ''
}
},
 
使用:
timestampToTime(2,时间戳)  //带时分秒
原文地址:https://www.cnblogs.com/lj8023/p/10483479.html