什么是时间戳
Unix时间戳(Unix timestamp),或称Unix时间(Unix time)、POSIX时间(POSIX time),是一种时间表示方式,定义为从格林威治时间1970年01月01日00时00分00秒起至现在的总秒数。
问题描述

解决代码
核心js代码
function add0(m){
return m<10?'0'+m:m } function format(shijianchuo) {
//shijianchuo是整数,否则要parseInt转换 var time = new Date(shijianchuo); var y = time.getFullYear(); var m = time.getMonth()+1; var d = time.getDate(); var h = time.getHours(); var mm = time.getMinutes(); var s = time.getSeconds(); return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s); }
在Vue项目中的使用
methods:{
// 转换时间戳为日期格式方法 add(m) {
return m < 10 ? "0" + m : m; }, format(shijianchuo) {
//shijianchuo是整数,否则要parseInt转换 var time = new Date(shijianchuo); var y = time.getFullYear(); var m = time.getMonth() + 1; var d = time.getDate(); var h = time.getHours(); var mm = time.getMinutes(); var s = time.getSeconds(); return ( y + "-" + this.add(m) + "-" + this.add(d) + " " + this.add(h) + ":" + this.add(mm) + ":" + this.add(s) ); }, }
methods:{
getOrderList() {
this.$http .get("orders", {
params: this.queryInfo, }) .then((res) => {
console.log(res); var temp = res.data.data.goods; // 将时间戳转换为日期格式 for (var i = 0; i < temp.length; i++) {
temp[i].create_time = this.format(temp[i].create_time); } this.orderList = temp; this.total = res.data.data.total; }); }, }
完活,成品展示

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/178512.html原文链接:https://javaforall.net
