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