首页 > js 解析时间戳出现的问题?

js 解析时间戳出现的问题?

demo在这https://jsfiddle.net/y4okbek1/36/,demo都测试好好的
但是项目中出现了问题。
console.log()输出
time变量为1441814400
解析出来就变成这样Thu Sep 10 2015 00:00:00 GMT+0800 (CST)


用momentjs,省心


LocaleString()会根据你机器的本地环境来返回字符串,它和toString()返回的值在不同的本地环境下使用的符号会有微妙的变化

你是需要输出2015-9-10 这样的?
那么你直接使用 var time =new Date(unix) ; time.getFullyear()+" "+time.getMonth()+"-"+time.getDay()

document.getElementById('searchbtn').addEventListener('click',function(){
    alert(getLocalTime(1441814400));
            });
 function getLocalTime(unix) {
        var time= new Date(parseInt(unix) * 1000);

      return time.getFullyear()+" "+time.getMonth()+"-"+time.getDay();
     }  
【热门文章】
【热门文章】