For example, if I run the following code on 1\14\2021 @3:04 PM EST locally:
const date = moment.utc().format('YYYY-MM-DD HH:mm:ss'); console.log(date); const stillUtc = moment.utc(date).toDate(); console.log (stillUtc); const local = moment(stillUtc).local().format('YYYY-MM-DD HH:mm:ss'); console.log(local); const jsLocal = new Date().toLocaleString() console.log(jsLocal);
I get the following output:
2021-01-14 20:04:04 Thu Jan 14 2021 15:04:04 GMT-0500 (Eastern Standard Time) 2021-01-14 15:04:04 1/14/2021, 3:04:04 PM
But if I run the same code via my monitor, I will get the following output:
2021-01-14 20:05:16 2021-01-14T20:05:16.000Z 2021-01-14 20:05:16 1/14/2021, 8:05:16 PM
Note each date is returned in UTC time when running via the monitor.
The problem occurs because I run my monitor at 10 PM EST nightly. When running at 10 PM EST on 1/13/2021, I will get the following returned:
2021-01-14T03:07:22.567Z 2021-01-14 03:07:22 2021-01-14T03:07:22.000Z 2021-01-14 03:07:22
If I wanted to test that the date is 1/13/2021 it will fail.
Does anyone have any workaround or another way that I could test for today’s date, keeping in mind I run my monitor at 10 PM EST nightly.
Thanks in advance.