# Is it possible to Date to keep incorrect time?

In search of an answer to the question "How to get the time in any different time zone from Date", on the English website, I came across an interesting version of the answer. It is proposed to completely ignore time zone, which makes Date, and suggest the following solution, which is given below:

``````function calcTime(city, offset) {
// create Date object for current location
var d = new Date();

// convert to msec
// subtract local time zone offset
// get UTC time in msec
var utc = d.getTime() - (d.getTimezoneOffset() * 60000);

// create new Date object for different city
// using supplied offset
var nd = new Date(utc + (3600000*offset));

// return time as a string
return "The local time for city"+ city +" is "+ nd.toLocaleString();
}

That is, completely ignored the timezone offset at the end of the row. And causing in different browsers this feature, the method new Date now will not convert to local time. Can I store the time and date? Is it right?
June 8th 19 at 17:25
June 8th 19 at 17:27
Solution
Impossible.

The first problem of this implementation is that first, the moment can not be 60000 milliseconds.
https://ru.wikipedia.org/wiki/%D0%A1%D0%B5%D0%BA%D...

The second is that we add to UTC (new Date) time in hours (3600000), and then get the time to current (toLocaleString) time zone, not the one we believe time. If the person that runs this code in this range will be the transition to winter and summer, the result it will give a wrong Date to convert the date to the current locale, and not the offset which gave.

And what's more - you can not generally specify the offset from UTC in hours because of winter-summer time definitely need to know the country and the city. The transitions in winter and summer - it's all a game of some sort, for each city may have their own rules of the clock, which, moreover, are subject to change. Therefore, in operating systems carry a huge reference to correctly calculate local time.

Here, for example, that in Russia happened over time, over the past 100 years: https://www.worldtimezone.com/dst_news/dst_news_ru...

The proposed function is almost always she will return the correct result, but will sometimes be wrong. Therefore, depending on the purpose of use. For financial documentation it cannot be used. And to output the current time on the website - why not.

Find more questions by tags JavaScript