smart-admin/rc-busness/static/js/date.js

30 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//时间戳转化成格式时间
import Vue from 'vue';
Vue.prototype.formatConversion = function (te){
if(te == ''){
return '';
}else if(te.length == 10){
var time = new Date(te * 1000); //时间戳为10位需*1000时间戳为13位的话不需乘1000
var y = time.getFullYear();
var m = time.getMonth() < 9 ? '0' + (time.getMonth() + 1) : time.getMonth() + 1;
var d = time.getDate() < 10 ? '0' + time.getDate() : time.getDate();
var h = time.getHours() < 10 ? '0' + time.getHours() : time.getHours();
var mm = time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes();
var s = time.getSeconds() < 10 ? '0' + time.getSeconds() : time.getSeconds();
//var timedate = y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s;
var timedate = y + '-' + m + '-' + d;
return timedate;
}else{
var time = new Date(te);
var y = time.getFullYear();
var m = time.getMonth() < 9 ? '0' + (time.getMonth() + 1) : time.getMonth() + 1;
var d = time.getDate() < 10 ? '0' + time.getDate() : time.getDate();
var h = time.getHours() < 10 ? '0' + time.getHours() : time.getHours();
var mm = time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes();
var s = time.getSeconds() < 10 ? '0' + time.getSeconds() : time.getSeconds();
//var timedate = y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s;
var timedate = y + '-' + m + '-' + d;
return timedate;
}
}