700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Vue 后端返回的时间戳如何解析为“yyyy-mm-dd hh:mm:ss“格式

Vue 后端返回的时间戳如何解析为“yyyy-mm-dd hh:mm:ss“格式

时间:2019-05-26 02:35:14

相关推荐

Vue 后端返回的时间戳如何解析为“yyyy-mm-dd hh:mm:ss“格式

方法一:js函数里var d=new Date(res.data.list[0].createTime);//res.data.list[0].createTime后端返的时间var time=d.toLocaleDateString()方法二:行内<el-table-column align="center" width="180" label="创建时间"><template slot-scope="scope">{{new Date(scope.row.createTime).toLocaleDateString()}}</template></el-table-column>方法三:灵活转换各种时间格式var now = new Date(res.data.list[0].createTime);var year = now.getFullYear();var Month = now.getMonth() + 1;var strDate = now.getDate();var Hours = now.getHours();var Minutes = now.getMinutes();var Seconds = now.getSeconds();if (Month >= 1 && Month <= 9) {Month = "0" + Month;}if (strDate >= 0 && strDate <= 9) {strDate = "0" + strDate;}if (Hours >= 0 && Hours <= 9) {Hours = "0" + Hours;}if (Minutes >= 0 && Minutes <= 9) {Minutes = "0" + Minutes;}if (Seconds >= 0 && Seconds <= 9) {Seconds = "0" + Seconds;}this.date=year+'年'+Month+'月'+strDate+'日'+" "+Hours+':'+Minutes

时间转换为时间戳

var date=new Date('-01-01')var dateNum=date.getTime()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。