Context: I have a server hosted on a VM in the cloud. When using just the moment
library to initialize dates I always get a date which has +- some hours. After a quick research, I found the moment-timezone
library which should solve this issue but I have some problems.
I have the following date: "transactionDate": "2020-08-25 18:30:00"
which gets submitted.
My code now looks like this where moment
is the moment-timezone
library now:
const momentTransactionDate = moment.tz(transactionDate, "YYYY-MM-DD HH:mm:ss", "Europe/Bucharest");
const formattedTransactionDate = momentTransactionDate.format(
"YYYY-MM-DD HH:mm:ss"
);
This will output the following values:
"momentTransactionDate": "2020-08-25T15:30:00.000Z",
"formattedTransactionDate": "2020-08-25 18:30:00",
For testing, I'm just doing a request from Postman to the local server.
Why is the momentTransactionDate
3 hours before, and why is the format()
function formatting a different hour?
Could someone explain how this is working?