How to keep the GMT timezone in X axis

i successfully manage to display a live graph but i faced a problem, when i want to get the GMT time zone, i mean, by passing the timestamp to x axis i don't want it to convert it to my local time zone.for example in python i had to use "utcfromtimestamp()" function.
as you can see in this photo the time zone here is GMT+1 which refer to my local time zone
node red question

and the timestamp i'm receiving from the client is "1585559327997" which is 30/03/2020 09:08:47:997
node red question 2

i'm not sure if this information would help but this is an example of the data i pass to the chart
[{
labels:,
series:['a', 'b'],
data:[
[{y:0.9, x:1585559327997},{y:0.8, x:1585559328297}],
[{y:0.02, x:1585559327997},{y:0.01, x:1585559328297}]
]
}]
X axis label is "HH:mm:ss SSS DD/MM/YYYY"

i did some research but nothing was helpful, most of people was asking for the local time zone which is the opposite of what i'm looking or :upside_down_face: and i tried this solution from this link
add the moment and moment-timezone library and then update the settings.js file:

functionGlobalContext: {
        moment:require('moment'),
        momenttz:require('moment-timezone')
    },

but i don't know what he mean by "and then using these libs in my functions.".
any suggestion will be appreciated.
best regard

Do you mean that on the graph it is correctly showing the time in your local timezone, but you actually want it displayed in GMT instead?

yes, exactly..

Set the timezone of the machine running the browser to GMT.
Though I realise the side effects of that may not be what you want.

and that's what i don't want to do :sweat_smile:
i don't want to change the browser settings or the machine setting to correct the node red program.
i was looking for a solution more like in the moment node, where i can just set the output TZ to "ETC/GMT+0"

Are you using the chart to show live data? In that mode you don't give it a timestamp at all.

yes, i'm showing a live data but the thing is, the time is come from the client itself, i get the time and the value, and because the client could be in somewhere else around the world, so it's better to display the time in GMT (to be precise, i should use the time i receive from the client in his time zone) so i need no GMT conversion.

When you chart live data you don't give it a time at all, you just give it a value and it uses the current time. So nothing you can do with a timestamp will change what it shows.

i'm not sure if i understand what you saying or not, but in my node i'm passing both and it woks fine, and to prove that, when i change the time zone of the client machine (add 1 hour), the time in the chart will change, i mean if the client machine send me a timestamp of (7:00 AM) (which is GMT+1) the chart display (8:00 AM) which will lead to add 2 hours in total. sorry for the bad example.

What sort of chart are we talking about here? Is it the standard node-red dashboard chart? To show live data you just send it values in msg.payload.

this one: https://github.com/node-red/node-red-dashboard/blob/master/Charts.md

and this is the payload i'm passing to the char node

[{
"series": ["A", "B", "C"],
"data": [
    [{ "x": 1504029632890, "y": 5 },
     { "x": 1504029636001, "y": 4 },
     { "x": 1504029638656, "y": 2 }
    ],
    [{ "x": 1504029633514, "y": 6 },
     { "x": 1504029636622, "y": 7 },
     { "x": 1504029639539, "y": 6 }
    ],
    [{ "x": 1504029634400, "y": 7 },
     { "x": 1504029637959, "y": 7 },
     { "x": 1504029640317, "y": 7 }
    ]
],
"labels": [""]
}]

And the first line there says
" To display live data just wire up an input with a msg.payload that contains a number"
but you are not doing that.

because if i do that, then the chart will use the local time zone (my time zone) the machine time zone, and i don't need that, i just want to convert the timestamp a GMT timezone and using the X axis, (i could use the moment node and convert in to string instead of using the chart time conversion but i couldn't pass string type :confused: )

The timestamps you are giving it (eg 1504029640317) are in GMT. The chart stores them in GMT and converts them to your local timezone when you display the chart.
The chart always shows 'now' at the right hand side and always shows the timescale in local time. That is the problem you have to address. You would need a change to the chart code to not convert it to local time for display.

1 Like

to correct myself, i'm not using the live chart. (sorry)

how can i do that?

You can check what I am saying by viewing the same chart from browsers on two different PCs, configured with different timezones. They will both show the most recent data at the right hand side but the timestamps will be the local time for that machine. So the problem is not in the data stored by node-red in the chart (which is in the machine running node-red not in the machines running the browsers) but in the way the timestamps are displayed by the browser.

1 Like

You could fork the github repository for the dashboard nodes and edit the code.
If you don't know what that means then I don't think this is a solution.

so you want to say, the solution is to change the timezone of the machine?
maybe if i get the local time zone and subtract it from the timestamp and pass it the the chart node, in this way maybe it's the better solution

i know what it means :stuck_out_tongue: but i always try to avoid changing a library code source, (at least i try my best to keep it the same and find a work arround)