码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-10-19 19:53:51      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

第一种

function getLocalTime(nS) {     
   return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,‘ ‘);     
}     
alert(getLocalTime(1293072805)); 

function getLocalTime(nS) {     
    return new Date(parseInt(nS) * 1000).toLocaleString().substr(0,17)}     
alert(getLocalTime(1293072805));  

技术分享

第二种

function formatDate(now) {
var year=now.getYear();
var month=now.getMonth()+1;
var date=now.getDate();
var hour=now.getHours();
var minute=now.getMinutes();
var second=now.getSeconds();
return "20"+year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;
}

var d=new Date(1230999938);
alert(formatDate(d));

技术分享



 

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

标签:

原文地址:http://www.cnblogs.com/sure2016/p/5978062.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!