当前位置: 代码迷 >> JavaScript >> JS怎么格式化Unix时间戳或日期Thu Apr 19 2012 16:00:00 GMT+0800,返回年月日
  详细解决方案

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

热度:214   发布时间:2012-09-24 13:49:41.0
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();//获取日 
  相关解决方案