简体   繁体   English

Chrome Javascript 日期构造函数错误?

[英]Chrome Javascript Date Constructor bugs?

I need to calculate a date and wrote the next.我需要计算一个日期并写下一个。

new Date(service.today().getTime() + (service.plazo * service.DAY_MILLISECONDS))

service.today = function() {
  var now = new Date();
  now.setHours(0,0,0,0);
  return now;
};

service.DAY_MILLISECONDS = 60*60*24*1000;

service.plazo is a number (1,2,3,4....) service.plazo 是一个数字 (1,2,3,4....)

the result结果

Wed May 18 2016 23:00:00 GMT-0300 (Hora est. Sudamérica Pacífico) 2016 年 5 月 18 日星期三 23:00:00 GMT-0300(Hora est. Sudamérica Pacífico)

i changed my timezone in my laptop: -3 to -4我在笔记本电脑中更改了时区:-3 到 -4

Wed May 18 2016 23:00:00 GMT-0400 (Hora est. Sudamérica Pacífico) 2016 年 5 月 18 日星期三 23:00:00 GMT-0400(Hora est. Sudamérica Pacífico)

all perfect BUT一切都完美但是

new Date()

Thu May 12 2016 16:19:51 GMT-0300 (Hora verano Sudamérica Pacífico) 2016 年 5 月 12 日星期四 16:19:51 GMT-0300(Hora verano Sudamérica Pacífico)

new Date(service.today().getTime() + (service.plazo * service.DAY_MILLISECONDS))

Wed May 18 2016 23:00:00 GMT-0400 (Hora est. Sudamérica Pacífico) 2016 年 5 月 18 日星期三 23:00:00 GMT-0400(Hora est. Sudamérica Pacífico)

new Date(service.today().getTime())

Thu May 12 2016 00:00:00 GMT-0300 (Hora verano Sudamérica Pacífico) 2016 年 5 月 12 日星期四 00:00:00 GMT-0300(Hora verano Sudamérica Pacífico)

new Date(service.plazo * service.DAY_MILLISECONDS)

Wed Jan 07 1970 21:00:00 GMT-0300 (Hora verano Sudamérica Pacífico) 1970 年 1 月 7 日星期三 21:00:00 GMT-0300(Hora verano Sudamérica Pacífico)

Why为什么

  • new Date()"新日期()”
  • new Date(service.today().getTime())新日期(service.today().getTime())
  • new Date(service.plazo * service.DAY_MILLISECONDS)新日期(service.plazo * service.DAY_MILLISECONDS)

is GMT-0300 and是 GMT-0300 和

  • new Date(service.today().getTime() + (service.plazo * service.DAY_MILLISECONDS))新日期(service.today().getTime() + (service.plazo * service.DAY_MILLISECONDS))

is GMT-0400是 GMT-0400

Chrome Version with error: 50.0.2661.94 m有错误的 Chrome 版本:50.0.2661.94 m

Chrome Version 46.0.2490.86 (64-bit) all is GMT-0400 :) Chrome 版本 46.0.2490.86(64 位)都是 GMT-0400 :)

Because of the time changes (standard time to daylight saving time), the timeZoneOffset will vary depending on which period the date you get falls.由于时间变化(标准时间到夏令时), timeZoneOffset将根据您获得的日期所属的时间段而有所不同。

I'm guessing daylight saving time ends may 14 in your country.我猜您所在国家/地区的夏令时将于 5 月 14 日结束。 This means that a date before May 14 will be GMT -0300, but with Hora verano Sudamérica Pacífico , and after you'll have -0400 but with Hora est. Sudamérica Pacífico .这意味着 5 月 14 日之前的日期将是 GMT -0300,但使用Hora verano Sudamérica Pacífico ,之后您将拥有-0400但使用Hora est. Sudamérica Pacífico

This way, you'll get the time that was the current time in your country at the specific date you're getting.这样,您将获得您所在国家/地区在您获得的特定日期的当前时间。 The time changes date and in general the timezone info are OS dependent, Chrome relies on your system settings to determine them.时间更改日期和通常时区信息取决于操作系统,Chrome 依赖您的系统设置来确定它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM