1、时间戳转换成常规的时间格式 ‘yyyy年MM月dd日 hh:mm:ss’ 或 'yyyy-MM-dd’等
// 如给定的时间戳是:"1559700659"
//第一步:时间戳为10位需*1000,时间戳为13位的话不需乘1000
let changesjc = new Date(1559700659* 1000);//转换成普通日期格式
let fk_time = _this.formatDate(changesjc, 'yyyy年MM月dd日 hh:mm:ss');
//输出fk_time 为:2019年06月05日 10:11:25
// [formatDate description]格式化时间 --start---
Vue.prototype.formatDate = function(date, fmt) {
if (!date) return '';
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
}
let o = {
'M+': date.getMonth() + 1,
'd+': date.getDate(),
'h+': date.getHours(),
'm+': date.getMinutes(),
's+': date.getSeconds()
};
for (let k in o) {
if (new RegExp(`(${k})`).test(fmt)) {
let str = o[k] + '';
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
}
}
return fmt;
};
2、普通日期转换成时间戳getTime();
sjcStart = Wed Jun 12 2019 00:00:00 GMT+0800 (中国标准时间);
now_sjc = sjcStart.getTime();
//输入 now_sjc 为 1560268800000