js时间戳转为日期格式

  1.js将时间转换成时间戳

var times1 = Date.parse(new Date());
var times2 = (new Date()).valueOf();
var times3 = new Date().getTime();

2.js获取制定时间戳的方法
var oldTime = (new Date("2015/06/23 08:00:20")).getTime()/1000;
getTime()返回数值的单位是毫秒

3.方法3
function formatDate(now) { 
     var year=now.getFullYear(); 
     var month=now.getMonth()+1; 
     var date=now.getDate(); 
     var hour=now.getHours(); 
     var minute=now.getMinutes(); 
     var second=now.getSeconds(); 
     return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second; 
} 
//如果记得时间戳是毫秒级的就需要*1000 不然就错了记得转换成整型
var d=new Date(1230999938); 
formatDate(d);
 
 

js时间戳转为日期格式

上一篇:git pull或git clone报错:error: RPC failed; curl 18 transfer closed with outstanding read data remaining


下一篇:QT https开发环境下通讯正常,打包后报 QNetworkReply::UnknownNetworkError错误