The question may sounds dumb, I am an absolute beginner.
So I want to store data in a csv file, and later on I want to display this data through a chart. I already tried to make a timestamp with msg.payload.timestamp = new Date() but that did not work with the chart node.
In the example from the chart node the timestamps are just numbers but I do not know how to create a timestamp that looks like that.
There is a great example flow you should import with lots of chart examples: https://flows.nodered.org/flow/2938d98507c81648a2ab5ac1ba6e7d31
give it a try and take a look at the examples and see if one of them answers your question (or generates more questions )
That x number is a JS internal timestamp -- it's the number of milliseconds since the epoch on 1/1/1970 00:00:00 GMT
The chart node inherently understands it as a timestamp and converts it to the local timezone for display. In JS, you can convert that to a human-readable Date object like so:
> new Date(1504029632890)
2017-08-29T18:00:32.890Z
> new Date(1504029632890).toString()
'Tue Aug 29 2017 14:00:32 GMT-0400 (Eastern Daylight Time)'
The first example is called ISO format, and is suitable for charts, as well as most databases. It is the only reliable format that should be used for internal datetime storage since it is not open to mis-interpretation. If you decide to store local timestamps, you will have problems reliably converting things like timezone offsets, daylight savings adjustments, and especially doing date arithmetic like time between 2 dates.
If you have a datetime string, many formats are recognized and can be parsed into an internal timestamp, like so:
Just be aware that the local timezone will be used if not given (notice the first 2 are the same for me in the Eastern US, while the 3rd uses Greenwich Mean Time).
Okay I fixed it, I just added 3600000 to the timestamp. The problem was that the chart node displays the time in GMT, i dont know how I can change this. There is probably a more elegant way to deal with this problem than just adding 3600000 milliseconds to the timestamp.
Yeah the node red server is running on my computer and I am accessing the ui on the same computer. Thats why I am confused why it shows the time in GMT
Are you going to the chart by reading the CSV file and displaying it on the chart? If so then show us how you are generating the timestamp to send to the chart, and show us what the file looks like.
While I was writing my answer I saw that in the chart node a checkbox with "show UTC" was activated. I just did not see it. So it does work, not anymore help needed. Still, thanks for your helpfulness!