前端 时间转换为时间戳 时间戳转时间


 时间戳转时间 

/**
使用方法:
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)

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM