首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

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

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

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();//获取日 

热点排行