Convert JS Time Zone

In Javascript, I have a timestamp that I process like this:

var origUnixTimestamp = (date * 1000);

Along with this timestamp, I have a UTC offset (-5, although this is a variable). I want to convert origUnixTimestamp to UTC offset of users using Date getTimezoneOffset () method.

I'm just wondering how I take into account the original UTC time offset (-5, for example) and convert it to the user's current UTC offset. I suppose it's pretty simple, but right now he's changing the brain.

+3
source share
3 answers

Javascript . , Date, ( ). Date UTC.

var some_date = new Date(epoch);
var time = some_date.getDay(); // will be different in different zones
some_date.setDay(22); // to set day
var origUnixTimestamp = some_date.getTime(); //returns you epoch
+3

This link contains instructions for converting from local time:

// create Date object for current location
d = new Date();

// convert to msec
// add local time zone offset
// get UTC time in msec
utc = d.getTime() + (d.getTimezoneOffset() * 60000);
0
source

Source: https://habr.com/ru/post/1725753/


All Articles