JS 日期與時間戳相互轉化


1、日期格式轉時間戳 

1 function getTimestamp(time) 
2 {
3     return Date.parse(new Date(time));
4 }

 

2、時間戳轉日期格式 

 1 function transformPHPTime(time) 
 2 {
 3     var date = new Date(time * 1000);
 4     
 5        Y = date.getFullYear() + '-';
 6     M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
 7     D = date.getDate() + ' ';
 8     h = date.getHours() + ':';
 9     m = date.getMinutes() + ':';
10     s = date.getSeconds();
11 
12     return Y+M+D+h+m+s;
13 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM