js new Date()不带时分秒时,时间变了 问题解决

//先把电脑系统时间的 时区 调到别的时间一下如 夏威夷 UTC-10:00
//在浏览器的Console里运行以下代码,getMonth是从0开始的,因此要+1浏览器

var d=new Date("2019-07-01")
console.log(d)
console.log(d.getFullYear()+"年"+(d.getMonth()+1)+"月"+d.getDate()+"日")

运行之后,竟然获得时间是6月30号.spa

 

解决办法,判断是要格式化的字符是否有:冒号,若是没有在后面加 00:00:00code

var d2=new Date("2019-07-01 00:00:00") //后面加00:00:00便可解决
console.log(d2)
console.log(d2.getFullYear()+"年"+(d2.getMonth()+1)+"月"+d2.getDate()+"日")

相关文章
相关标签/搜索