读书人

JS怎么格式化Unix时间戳或日期Thu Apr

发布时间: 2012-09-24 13:49:41 作者: rapoo

JS如何格式化Unix时间戳或日期Thu Apr 19 2012 16:00:00 GMT+0800,返回年月日
JS如何格式化这种日期Thu Apr 19 2012 16:00:00 GMT+0800,返回年月日

或者Unix时间戳(Unix timestamp)是1346747298 如何通过JS,返回年月日呢?

[解决办法]
看注释

HTML code
<!doctype html><html><head>    <title>test</title>    <script type="text/javascript">        var myDate = new Date();        alert(myDate);        alert(myDate.getFullYear());        alert(myDate.getMonth());        alert(myDate.getDay()); //其他以此类推 你想组装成什么格式自己决定        var unixDate = 1346747298;                myDate = new Date(unixDate);        alert(myDate); //此时已经转换为Thu Apr 19 2012 16:00:00 GMT+0800这种格式 格式化就按照上面的来就行了    </script></head><body></body></html>
[解决办法]
JScript code
var dt= new Date('1346747298');var year=dt.getFullYear();//获取年var month=dt.getMonth();//获取月var day=dt.getDay();//获取日 

读书人网 >JavaScript

热点推荐