toDateString()减少我的日期 [英] toDateString() decrements my date

查看:77
本文介绍了toDateString()减少我的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于以下代码:

var d = new Date("2013-07-01");
console.log(d.toDateString());

它输出2013年6月30日,这是输入的一天。对象发生了什么事?实际存储的日期是什么?

It outputs Sun Jun 30 2013, which is one day less of what was input. What happened to the object? What date is actually stored?

推荐答案

日期被解析为UTC日期,但 toDateString() 输出本地时区的时间。

The date is parsed as UTC date, but the toDateString() outputs what that time is in the local timezone.

尝试这样做

var d = new Date(2013, 6, 1); //6 instead of 7 because the mont argument is  zero-based
console.log(d.toDateString());




实际存储了什么日期?

What date is actually stored?

2013-07-01 00:00:00 UTC

2013-07-01 00:00:00 UTC

这篇关于toDateString()减少我的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆