前端 時間轉換為時間戳 時間戳轉時間


 時間戳轉時間 

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