I have Raspberry Pi with node-red installed and I need get timestamp from client browser to syncronize it with server timestamp (because Raspberry Pi doesnt have RTC source).
With Dashboard 1.0 it was easy with periodically (every 5 second) triggered template with script like this
<script>
(function(scope){
scope.$watch('msg', function(msg) {
var Datum = new Date();
scope.send({payload: Datum});
});
})(scope);
</script>
When page in focus I got a payload with timestamp every 5 seconds -
msg.payload : string[24]
"2026-05-01T08:28:12.418Z"
But when I migrate to Dashboard 2.0 this code didn`t work at all. Maybe somtbody get advice how to get it work.
There is, of course, a better solution still - assuming you have Internet access. Configure your Pi to use a public time server. I thought that would happen automatically with a Rasbian install actually but maybe I'm wrong - been a while since I used a Pi.
A Pi (Raspberry Pi OS) will synchronise with an NTP server as soon as it has internet access.
You can verify it by running the command timedatectl.
Here is the output on one of my Pies. It shows that the clock is indeed synced.
pi@orangepi:~ $ timedatectl
Local time: Fri 2026-05-01 12:16:32 BST
Universal time: Fri 2026-05-01 11:16:32 UTC
RTC time: n/a
Time zone: Europe/London (BST, +0100)
System clock synchronized: yes ***** <=== THIS IS THE IMPORTANT BIT *****
NTP service: active ***** AND THIS *****
RTC in local TZ: no
Note that the only time sync in the logs (sudo journalctl -u systemd-timesyncd) was at startup 7 days ago, and the conf file /etc/systemd/timesyncd.conf is the default (everything commented out)
AI assures me this is because the clock has not yet acquired sufficient drift to require a sync.
Yes, with internet access Raspbian does all time sync automatically.
But my system without internet access, so easy way to sync time - is to get timestamp from the client device browser in numerical form then add/subtract timezone then use node like node-red-contrib-moment to get human readable date/time.
Another way - add to Raspberry Pi hardware RTC and battery, but it's not so convinient, also this way I need to add in hardware possibility to change RTC battery.
With UIBUILDER, it passes the servers timestamp to the client on connection but that is more for working out if the 2 are in different timezones but it could be used to sync times I suppose. Doesn't really help you with D2 though I'm afraid.