var unixTimestamp = new Date( 1477386005*1000 ) ;//获取时间戳 commonTime = unixTimestamp.toLocaleString();//转换为yyyymmddhhmmss格式
//具体实现方法
Date.prototype.toLocaleString = function() { return this.getFullYear() + "年" + (this.getMonth() + 1) + "月" + this.getDate() + "日 " + this.getHours() + "点" + this.getMinutes() + "分" + this.getSeconds() + "秒"; };
本文介绍了一个具体的JavaScript实例,演示如何将Unix时间戳转换为本地可读的时间格式。通过自定义Date对象的方法,实现了时间戳到指定格式字符串的转换。
480

被折叠的 条评论
为什么被折叠?



