js把时间戳转换为普通php日期格式


 

 

function formatDate(now) { 
var year=now.getFullYear();  //取得4位数的年份
var month=now.getMonth()+1;  //取得日期中的月份,其中0表示1月,11表示12月
var date=now.getDate();      //返回日期月份中的天数(1到31)
var hour=now.getHours();     //返回日期中的小时数(0到23)
var minute=now.getMinutes(); //返回日期中的分钟数(0到59)
var second=now.getSeconds(); //返回日期中的秒数(0到59)
return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second; 
} 
var g=1551334252272; //定义一个时间戳变量
var d=new Date(g);   //创建一个指定的日期对象
console.log(d);
console.log(formatDate(d));

js把时间戳转换为普通日期格式


免责声明!

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



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