In Javascript / NodeJS, return the current date set to the time zone, then find the UTC equivalent of the user's time at 6am

Sorry if the title is a bit confusing. I stomp my head on the floor with time in NodeJS/ Javascript. I can get the current UTC time as follows:

var currentTime = Date.now();

I can get the current time for a user who, for example, is in the time zone -3as follows:

var offsetTime = Date.now() + (numTimeZone * 3600000);

But how do I get the user's local time, say, 6am, converted to UTC?

Practical application :

What I'm trying to do is create an auto-emailer that sends an email to the user at 6am local time. My server is in one time zone, and they will be in another, so I try to standardize it against UTC, so every minute I can set my server to check the time currentUTC, and then check that the 6am user time is converted to UTC ( local6am), and if currentUTC > local6amthen you should send an email.

What is the best way to achieve this? Preferably, if not using the library, if possible.

+4
source share
1 answer

Utc to local

moment.utc('2014-02-19 05:24:32 AM').toDate();

Local for utc

.

MomentJS . , .

UTC, , . UTC + N, .

moment(new Date('02-19-2014')).utc().format("YYYY-MM-DD HH:mm").toString()

moment(new Date('02-19-2014 12:00')).utc().format("YYYY-MM-DD HH:mm").toString()

()

:

moment.utc('07-18-2013', 'MM-DD-YYYY')

moment.utc('07-18-2013', 'MM-DD-YYYY').format('YYYY-MM-DD')

toString.

+2

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


All Articles