I am in Israel, so my offset right now should be 120
. Yet, when I use new Date().getTimezoneOffset()
, I get back -120
, so not just a daylight savings issue.
Should I simply change every minus to plus and vice versa? I don't know what might be the case for users in other timezones.
That's my function:
firebase
.database()
.ref("words/" + newPostKey)
.set({
word,
length: word.length,
time_to_action: timeToAction,
output: output,
lang: project.lang,
country: project.country,
user: userUID,
timestamp : Date.now(),
timezone_offset : new Date().getTimezoneOffset()
});
and timezone_offset
is what gets saved as -120
. I am in Tel Aviv.
I am in Israel, so my offset right now should be 120
. Yet, when I use new Date().getTimezoneOffset()
, I get back -120
, so not just a daylight savings issue.
Should I simply change every minus to plus and vice versa? I don't know what might be the case for users in other timezones.
That's my function:
firebase
.database()
.ref("words/" + newPostKey)
.set({
word,
length: word.length,
time_to_action: timeToAction,
output: output,
lang: project.lang,
country: project.country,
user: userUID,
timestamp : Date.now(),
timezone_offset : new Date().getTimezoneOffset()
});
and timezone_offset
is what gets saved as -120
. I am in Tel Aviv.
- 1 developer.mozilla/en-US/docs/Web/JavaScript/Reference/… “returns the time zone difference, in minutes, from current locale (host system settings) to UTC” - “I am in Israel, so my offset right now should be 120” - that is simply the other direction, from UTC to your locale. – misorude Commented Feb 13, 2020 at 12:12
3 Answers
Reset to default 4getTimezoneOffset()
is working well. This function retuns the number of minutes you have to add to your current time to get the UTC time, so in GMT+X the result is negative.
Well, I live in Ukraine and even if we have (UTC + 02: 00) now we are ahead of UTC by 3 hours cause we have 'winter time', when clocks are set back by one hour. So new Date().GetTimezoneOffset()
returned '-120'
, while new Date(0).getTimezoneOffset()
returned '-180'
. Maybe that's the case you faced with.
Yes. You are ahead of GMT by 2 hours therefor to get back to GMT you have to subtract 120 minutes. Your offset is -120.