时间戳转moment时间的时候,需要毫秒,就是13位时间戳
let start = this.formatNumber(item.eventStartTs);
let end = this.formatNumber(item.eventEndTs);
//时间戳回填date-picker
this.workListItem["date"] = [moment(start).format(), moment(end).format()];
<a-range-picker
v-model="form.date"
@change="dateChange"
:placeholder="['开始时间', '结束时间']"
style="width: 280px"/>
data(){
return{
form{
//一周前-当前时间
date: [moment().subtract(1, 'weeks').startOf('day'), moment().endOf('day')],
}
}
},
methods:{
dateChange(date, dateString) {
this.form.date = date;//保证校验成功后去掉红字提示
//转时间戳方法(10位)
// let beginT = Math.round(new Date(dateString[0] + ' 00:00:00')/1000);
// let endT = Math.round(new Date(dateString[1] + ' 23:59:59')/1000);
let beginT = this.momentToTimeStamp(moment(date[0]).startOf('day'));
let endT = this.momentToTimeStamp(moment(date[1]).endOf('day'));
this.postEventData["startTimeStamp"] = beginT;
this.postEventData["endTimeStamp"] = endT;
},
//这里要注意,时间戳转moment时间的时候,需要毫秒,就是13位时间戳。如果是10位的话,时间会出错
formatNumber(number){
let flag = number + '';
let retNum = flag.length == 10 ? flag + '000' : flag;
console.log("fffformat--number:", parseInt(retNum));
return parseInt(retNum)
},
momentToTimeStamp(time){
return parseInt(time.format('X'))
},
}
网友评论