扫码关注官方订阅号
demo在这https://jsfiddle.net/y4okbek1/36/,demo都测试好好的但是项目中出现了问题。console.log()输出time变量为1441814400解析出来就变成这样Thu Sep 10 2015 00:00:00 GMT+0800 (CST)
人生最曼妙的风景,竟是内心的淡定与从容!
LocaleString()会根据你机器的本地环境来返回字符串,它和toString()返回的值在不同的本地环境下使用的符号会有微妙的变化
你是需要输出2015-9-10 这样的?那么你直接使用 var time =new Date(unix) ; time.getFullyear()+" "+time.getMonth()+"-"+time.getDay()
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(); }
用momentjs,省心
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
LocaleString()会根据你机器的本地环境来返回字符串,它和toString()返回的值在不同的本地环境下使用的符号会有微妙的变化
你是需要输出2015-9-10 这样的?
那么你直接使用
var time =new Date(unix) ; time.getFullyear()+" "+time.getMonth()+"-"+time.getDay()
用momentjs,省心