首页 >web前端 >js教程 >js时间戳转换日期

js时间戳转换日期

PHP中文网
PHP中文网原创
2017-07-12 18:10:311249浏览
<span style="color: #0000ff">//js时间戳转换日期<br>function</span><span style="color: #000000"> formatDate(now) {
    </span><span style="color: #0000ff">var</span> year=<span style="color: #000000">now.getFullYear();
    </span><span style="color: #0000ff">var</span> month=now.getMonth()+1<span style="color: #000000">;
    </span><span style="color: #0000ff">var</span> date=<span style="color: #000000">now.getDate();
    </span><span style="color: #0000ff">var</span> hour=<span style="color: #000000">now.getHours();
    </span><span style="color: #0000ff">var</span> minute=<span style="color: #000000">now.getMinutes();
    </span><span style="color: #0000ff">var</span> second=<span style="color: #000000">now.getSeconds();
    </span><span style="color: #0000ff">return</span> year+"-"+month+"-"+date+" "+hour+":"+minute+":"+<span style="color: #000000">second;
}

</span><span style="color: #0000ff">var</span> d=<span style="color: #0000ff">new</span><span style="color: #000000"> Date(时间戳(毫秒));
alert(formatDate(d));</span>

 

以上是js时间戳转换日期的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn