Currently, I am in the process of developing an app using Firebase as the server and Flutter for the frontend. The situation I am facing is that when I upload a new document with a timestamp containing the current time in this format:
"timestamp": DateTime.now().toString(),
When running it on localhost, I noticed that the document saves the current time accurately. However, when running it on the cloud server, it adds 3 hours to the timestamp. I understand that this discrepancy is likely due to the UTC time zone difference, where my country's UTC is +3. The relevant line of code on the server is:
console.log(req.body.timestamp);
let timeStamp = new Date(req.body.timestamp);
console.log(timeStamp);
For instance, the output on localhost for timestamp string 2020-05-23 23:16:03.735472
was displayed as:
> 2020-05-23 23:16:03.735472
> 2020-05-23T20:16:03.735Z
However, when viewed from the server, it appeared as:
> 2020-05-23 23:16:03.735472
> 2020-05-23T23:16:03.735Z
The question remains - why does this happen?