Node red time zones offset in Dashboard chart

As you mentioned, your formatted date and time string is from TZ Europe/London (GMT).

And you want convert to GMT + 8 ?

What is doing the conversion to GMT + 8 ? chart.js ?

Did you provide (already) a sample of the data you send to your chart.js function / node?

Since you already have the unix timestamp, you can just convert this to a formatted time string for GMT + 8 and pass it on to your chart (I assume, without seeing the raw chart data).

There are two ways to do this.

The "right way" is to use some function code or node which will take the unix timestamp and convert this to a GMT + 8 formatted time string.

The "wrong way" to do this is ... <deleted> :slight_smile:

If you want, please provide some sample chart data which includes enough samples to understand the format of this chart data.

Did you provide this already and I missed it?

That isn't the correct unix time, for 1/1/2020 01:00:00 local time, it is the unix timestamp for 1/1/2020 01:00:00 UTC. So that is why the timestamp on the chart it wrong, it is expecting it to be given the timestamp in UTC, and it will display it in local time. Is the timestamp supposed to be the current time? If so the easiest way is probably to determine the timestamp in node-red, you can do this using

timestamp = Date.now().getUnixTime()

Then you should be able to feed that straight to the chart.

Nevermind.... :slight_smile:

Until I see the actual raw data going to chart.js showing the data and the times, I'm on the sidelines.

You are in good hands with @colin on this one!

Hello Colin, it gives me error on using
Date.Now().getUnixTime()

Here is my code:

 var new_msg_target = {"x":new Date(time).getUnixTime(), "y": parseFloat(val)}

Error is:
getUnitTime is not a function.

time variable holds the 1/1/2020 this kind of type of date format.
Thanks !

Hello This code is working:

var new_msg_target = {"x":new Date(time.replace(' ', 'T')).getTime(), "y": parseFloat(val)}

Any suggestions/comments?

Dear All,

Thank you for all of your help. I found a way now on how to correct it, I just actually discovered that in Chart js, it can accept date format to be "yyyy-MM-dd HH:mm:ss", this is a 24 hour format like this: "2020-01-02 02:00:00" , so on the side of my .Net application I just need to format my time to be like that and node-red can understand it. no need to translate it on unix time. Don't know why I did not discovered it before.

Again, Thank you for all your support!

Regards

Yes, sorry, getting my languages mixed up. It should be

{x: (new Date()).getTime()/1000, Y: ..}

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