I've added the date/time in my dashboards toolbar as discussed right here.
It's working fine but it doesn't quite fit my needs because I need the local time of the raspberry to be displayed (The interface will always be launched from different devices). Currently it shows the time of the device accessing the dashboard (Because the Code is executed clientsided). It is really important to me to have the functionality to check the local time of the raspberry because sometimes the time can't be synchronized automatically. This has to be checked for messurements and later I want to implement the functionality so the user has the ability to change the date/time manually.
My question is: What is the easiest way to get the job done?
I believe there's a bit of confusion here. There are two things: the time and the representation. You are sending the time from the server IIUC, so the time displayed is the time of the server (rPi). That time is a number (milliseconds since 1970-1-1 UTC). You're asking the browser to format it and it's nice to you by using your local time zone to format it. You could change your code a bit to format it using the UTC time zone. But however you format it, it's still the time of the server.
Yes, but if @JustinB wants to display it in the browser, using the time zone of the server to format it, he will need to convert it to a string in the server and send that to the browser. Or, I suppose, send the timezone offset to the browser to use when formatting it, but I think it would be easier to convert it in the server.
His "problem statement" has "It is really important to me to have the functionality to check the local time of the raspberry because sometimes the time can't be synchronized automatically." This does not state or imply that the time has to be shown in the time zone of the server. If he wants to make sure that the time zone is set correctly it's best to display the name of the time zone. To compare the time of the server to, say, the time on a smartphone it's probably best to show the time in the browser's local time 'cause that's presumably what the smartphone will display as well.
You are correct that if the time zone of the server is desired then formatting it on the server is best.
Note that time synchronization does not have anything to do with time zone.
NB: if you send the time in milliseconds to the browser you could also display the difference, which, if the machine the browser runs on has synchronized time, could even allow you to color the delta-time in green/yellow/red depending on thresholds...
@Colin is right. It's important to me to see the current time of the server/pi.
The background is the following: I created a Interface which you can connect to a control unit. This control unit is wired with multiple sensors. The main functionality is to do messurements in a desired interval. The results are collected in a database. The reason why it is so important to see the current time of the pi is that there is a functionality to select a period of time when the messurements have to be done.
If the time of the server/pi is incorrect, the messurement will be done at the wrong time.
What is the best way to get the time of the server and send it to the browser? When retrieving the time from a normal function node, will it display the time of the server?
I've read the documentation but I'm a bit confused. What exactly is this doing? As I understood, the time of the user accessing (in my case) the interface is getting compared to the time of the server/pi? Or did I misunderstood something?
It returns the timezone offset of the server (or where ever you run the function). You would then send that in the template node to the browser. In the browser you use the timezone offset in the toLocaleString(), you can set an option of timezone. The browser should then convert the date object to a string, which would be set to the correct time zone.
I thought about displaying the raw, naked time of the server. Without any formatting. Something like getting the time locally from serverside and sending the result every 5 seconds to the template node which will just display it as a text
In computers, time is stored in UTC with a timezone offset that can be used to display it in a particular timezone. If I am in a zone UTC+1 and you are in UTC-1 and I talk to you on the phone we are both talking at the same time. There is only one time (unless you want to get into Einstein's relativity). If the pi and browser are in different timezones, but both have the clocks set correctly, then the time in pi and the time in the browser are the same. The only difference is that when they are displayed the time is formatted so they display in the local timezone of the user. It is only a formatting issue, not a time difference issue.