1

I have a program that uses the Date object in JavaScript. I've noticed that the program is not working properly in all time zones (countries).

So I've changed my Windows time zone and I got strange results in specific dates.

With these lines of codes I have same results in many Time Zones but one of them (maybe some):

console.log( new Date( 2005, 2, 20 ) ); // 2005 Mar 20
console.log( new Date( 2006, 2, 20 ) ); // 2006 Mar 20


Time Zone: UTC 00:00 (Correct) enter image description here

Time Zone: Pacific (US & Canada) -08:00 (Correct) enter image description here

Time Zone: Newfoundland -03:30 (Correct) enter image description here

Time Zone: China +08:00 (Correct) enter image description here

Time Zone: Iran +03:30 (Incorrect!) enter image description here

(Notice the 19 Mar and 23:00:00 and Daylight vs. Standard)
(I've tested the problem in Chrome with the same result)

I've solved the problem with this solution:

new Date( Date.UTC(2005, 2, 20) );

But I want to know what happens here?
Is +03:30 has any bugs? What is the difference between Daylight and Standard?

That's weird...

3
  • You are familiar with Daylight Savings Time (DST) right? It looks like DST happens in the night of March 19th in Iran. Commented Feb 8, 2013 at 12:10
  • I mean why this happens in the problem? Commented Feb 8, 2013 at 12:11
  • 2
    They changed how DST is observed in 2006. en.wikipedia.org/wiki/Daylight_saving_time_in_Iran Commented Feb 8, 2013 at 12:14

2 Answers 2

1

There is no problem with date object. Some countries observe daylight savings during spring and autumn season to get more daylight time. Check Here. It just so happened that on 20 March 2005 Iran's time was subject to daylight savings. Showing you correctly what time they were observing (Notice that the difference with GMT changed from +0430 to +0330). Where as on that day in year 2006 they were following the regular time and not subject to daylight savings.

Refer to "Frits van Campen" link in the comments.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes that will work perfect. It is legally and technically correct date and time that you are getting.
0

You should unify the time zone for or make the timeZone appearing as the customer time zome. For Example for Australia, I use below for AU Sydney time Zone

let expirationTime = new Date().toLocaleString("en-US", {timeZone: "Australia/Sydney"});
expirationTime = new Date(expirationTime);

I hope that helps ☺

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.