date js 减去_javascript – 为什么js从具有特定格式的Date对象中减去一天?

有些浏览器将部分日期字符串解析为UTC,有些则解析为本地时间,

因此,当您阅读它时,本地化时间可能因浏览器而异

按时区偏移量.

您可以强制Date为UTC并添加本地偏移量

希望时间得到保证:

1. set UTC time:

var D= new Date("2015-02-01"+'T00:00:00Z');

2. adjust for local:

D.setMinutes(D.getMinutes()+D.getTimezoneOffset());

D的值:(本地日期)

Sun Feb 01 2015 00:00:00 GMT-0500(东部标准时间)

抵消将是当地时间.

Some differences between browsers when time zone is not specified in a parsed string:

(tested on Eastern Standard Time location)

(new Date("2015-02-01T00:00:00")).toUTCString();

Firefox 35: Sun, 01 Feb 2015 05:00:00 GMT

Chrome 40: Sun, 01 Feb 2015 00:00:00 GMT

Opera 27: Sun, 01 Feb 2015 00:00:00 GMT

IE 11: Sun, 01 Feb 2015 05:00:00 GMT

IE and Firefox set the Date as if it was local, Chrome and Opera as if it was UTC.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值