Why does node-red convert time to utc.
I have records in a mysql data that is stored in local time.
When you execute the stored procedure from phpMyAdmin, the datetime field is correct, but for some reason the mysql connector appears to return the datatime in UTC.
I've set the timezone on the pi and the mysql timezone is using system.
There is a location were I can set the default timezone for node-red.
Answered my own question:
var tz_offset = (new Date()).getTimezoneOffset() * 60 * 1000
let r = msg.payload[0];
let data = [r.map( v => ({
"dtStart": new Date(v.dtStart.getTime() - tz_offset),
"dtEnd" : new Date(v.End.getTime() - tz_offset),
}))];
Really, don't do that. Always use UTC for storing timestamps, then convert when you want to display it.
When you have local time stored consider what you see when you look back at records saved on the morning when the clocks go back at a time just after the clocks go back. So if they go back to 03:00 to 02:00. If you fine 02:30 you don't know whether that is 02:30 UTC or 01:30 UTC - both of which are 02:30 local time (adjust the times here for you local timezone but the effect is the same). However there is no issue converting from UTC to local time.
The default for storing and processing date/time values should always be UTC. That's to avoid timezone and DST processing errors. You should generally only ever convert to local time on display. If you don't do this, you have to be very careful about each step of your processing, storage and display.