
下面是封装好的一个函数,直接上代码
function trans(unixTime, isFull, timeZone) {
if (typeof (timeZone) == 'number')
{
unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
}
var time = new Date(unixTime * 1000);
var ymdhis = "";
ymdhis += time.getUTCFullYear() + "-";
ymdhis += (time.getUTCMonth()+1) + "-";
ymdhis += time.getUTCDate();
if (isFull === true)
{
ymdhis += " " + time.getUTCHours() + ":";
ymdhis += time.getUTCMinutes() + ":";
ymdhis += time.getUTCSeconds();
}
return ymdhis;
}
第一个参数放时间戳,第二个参数为 true 则显示时分秒,第三个为时区,东八区直接输入 8.
原创文章转载请注明:转载自:js中如何格式化时间戳
发表评论
沙发空缺中,还不快抢~