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.
Advertisement
Answer
getTimezoneOffset()
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.