Timestamp and GMT value problem

Hello to all. I am handling and manipulating data from a database. Each data has its own timestamp, which was taken in UTC, as this data comes from different parts of the world. This data must be converted into a table in order to be exported, but the date must be shown according to the timezone of the person doing the export. I am using the function .getTimezoneOffset, so with that value I can add or subtract from the timestamp and the dates are shown in the correct zone, but the function always throws me the value of 0. I am sure that Node-Red knows the correct timezone because in the debug screen when I print a timestamp, I can show it with GMT-5, and I also tested with a VPN in different countries, but I need to be able to put that "-5" in a variable.

I look forward to your help

Node-RED knows "your" timezone. But that isn't necessarily the tz of the user of course.

I would question the need for the export to do the conversion. Why not get any final report to do that since it is likely that will be done by a local user and so the system would know the correct local tz at point of report production. That is the recommended and safe way in any case. Always store and process timestamps in UTC and only use local tz for user data collection and user display.

Thank you for your response. Node-Red is running on an AWS instance, EC2. I am in Latin America and the debug screen does show me that my GMT is -5. I tested with a VPN and indeed when I placed myself in another country, the GMT was updated. The machines from which I receive data are not fixed and travel around the world, and likewise the users that access that information are from different parts of the world, so I cannot set a zone as constant. I do not know if this solves the doubts about the post.

Hard to work out what you are actually doing without some code to look at. But does the device know what timezone it is in when recording the data? And do you need to know the timezone where the data is recorded?

No, the device doesn't know the tz, so always use UTC. It's not important to know where the data was recorder, what I need is the tz of the people who is extracting data from Node-Red. I'm looking the way to know the GMT value using function nodes, so I can show the date depending where is the user!

The tz of a user should be available from the browser. So are the users in the Editor or in Dashboard or something else?

For example, with uibuilder, when a client connects, they get an initial connection msg that, amongst other things, contains the server's timestamp. The uibuilder front-end client library compares that with the browser timestamp and records the offset. But that all happens in the front-end, not the back-end. Converting from UTC to local should happen in the front-end as I mentioned before.

1 Like

The user is in the dashboard, he has access to a date picker and a time picker. The user select two dates and two times, in order to show a database in form of a table. I extract the information from a database using a HTTP request, but if people is in other country, I need to add or rest the GMT value before to make the HTTP request, so that's why I need the GMT value in the back-end

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.