zhukaixin

 时间戳转时间 

/**
使用方法:
this.endValue = this.dataFormat(resultEnd, "Y-m-d H:i:s")

 

 

*/

dataFormat(timestamp, formats) {
// formats格式包括 // 1. Y-m-d // 2. Y-m-d H:i:s // 3. Y年m月d日 // 4. Y年m月d日 H时i分 formats = formats || \'Y-m-d\'; let zero = function (value) { if (value < 10) { return \'0\' + value; } return value; }; let myDate = timestamp ? new Date(timestamp) : new Date(); let year = myDate.getFullYear(); let month = zero(myDate.getMonth() + 1); let day = zero(myDate.getDate()); let hour = zero(myDate.getHours()); let minite = zero(myDate.getMinutes()); let second = zero(myDate.getSeconds()); return formats.replace(/Y|m|d|H|i|s/ig, function (matches) { return ({ Y: year, m: month, d: day, H: hour, i: minite, s: second })[matches]; }); }

时间转换为时间戳

 
/**
当前时间转为时间戳
*/
let myDate = new Date(); let time = myDate.getFullYear() + \'/\' + (myDate.getMonth() + 1) + \'/\' + (myDate.getDate()) + \' \' + myDate.getHours() + \':\' + myDate.getMinutes() + \':\' + myDate.getSeconds(); let resultStart = Date.parse(time) - (28 * 3600000)

 

 

分类:

技术点:

相关文章: