Node-RED Time-Format Node-Status

image

The time format of some status nodes is in the 12-hour clock format. I want to change this to the 24-hour format, but I don’t know where to do it.

The system environment is set to German/Austria, so this shouldn’t be the issue.

If your timezone is set correctly, you can adjust the time format for the status display in the Home Assistant server config node.

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/config-server.html#status-date-format

image

Thanks, that worked well. But I have the same problem with the KNX-Ultimate-nodes. And there, I can’t find anything in the configuration node.

image

The text under the node is created by the node itself. The configuration you changed Is for HA nodes only. You would need to look at the knx node itself to see if it’s format could be changed.

Yes, I know, but in the KNX node there is no such setting option.

I switched from ioBroker to HA, and there I had the 24-hour format. I believe that HA uses the 12-hour format by default if nothing more specific has been configured. And I hope to find a way to change this default behavior.

HA uses your locale’s default format. You can change this on a per user basis by clicking on your profile pic, last icon bottom left. However this is only for ha dashboards.

Ha and NR are 2 separate programs, independent of each other. In NR the node generates the message under the node, including how it’s formatted. If it’s not adjustable, you’ll need to ask the node’s maintainer to add that option.

Hi, i’ve fixed that in KNX Ultimate, by allowing a custom datetime formatting in the config window.

1 Like

I would like to raise the same question.
I understand Kermit is the maintainer, isn’t he?

I’m getting the date in format month/day/year, which is incorrect for my location. The correct one is day-month-year, and the one preferred by me is year-month-day
I see no option to modify that in the server node (see screenshot).
How can I change that?

The server uses Intl.DateTimeFormat.prototype.resolvedOptions() to determine the locale. If no locale is found, it falls back to en-US. That locale is then used to format the date in the status string based on the options selected in the Server node configuration.

https://github.com/zachowj/node-red-contrib-home-assistant-websocket/blob/73a9e68bb3f00282b905b645f5ec3e67da1f3e2d/src/helpers/date.ts

You can run the following to see which locale your Node-RED server is using.

[{"id":"3f1037eb163d23ab","type":"inject","z":"c89d915bdff0f798","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":960,"wires":[["f21c7bfab05e01e4"]]},{"id":"f21c7bfab05e01e4","type":"exec","z":"c89d915bdff0f798","command":"node -e \"console.log(Intl.DateTimeFormat().resolvedOptions())\"","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":516,"y":960,"wires":[["7b2e4a4bc5f6afc0"],[],[]]},{"id":"7b2e4a4bc5f6afc0","type":"debug","z":"c89d915bdff0f798","name":"debug 17","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":852,"y":960,"wires":[]}]

Thank you…
Here is the result:

{
  locale: 'en-US',
  calendar: 'gregory',
  numberingSystem: 'latn',
  timeZone: 'Europe/Prague',
  year: 'numeric',
  month: 'numeric',
  day: 'numeric'
}

Please note that it’s NR addon, run on HAOS.
I’m not aware of locale selection being offered on HAOS installation (it was long ago), but even though it’s likely I chose some English default (because of the English language). But in terms of date formatting, I prefer Y-M-d format, regardless of the language.

You learn something new every day.

Home Assistant offers both timezone setting, and locale setting. Timezone is set once on installation, but can also be set/changed in the Settings > System > General, so for myself I have Europe/London.

Locale settings are more complicated, and are set for each user. This is done via the user icon in the menu (bottom left), so it would appear that you can only set these for yourself and only when logged in.

So, for myself I have set the Language to English(GB) which probably drives the user locale as en-GB. The following number/time/date formats are then driven from this as ‘auto’ which uses the set locale, or something else from a pick-list.

You can see that the HA user locale date is auto (which is 12/01/2026 as I am set to en-GB) or system (which is 1/12/2026 since the system default is en-US). We also have day-month-year and month-day-year, and year-month-day.

All fine for Home Assistant.

Node-RED, on this machine, runs as an add-on. Using Kermit’s flow, the extracted locale for my Node-RED instance is:

{
  locale: 'en-US',
  calendar: 'gregory',
  numberingSystem: 'latn',
  timeZone: 'Europe/London',
  year: 'numeric',
  month: 'numeric',
  day: 'numeric'
}

which is interesting. I know that HA hands the timezone setting to Node-RED as an addon, using the environment variable TZ, however this does indicate that the (assumed) locale setting is probably not being handed to the add-on docker.

Since add-ons are started by the supervisor, I guess the locale must come from the supervsior docker startup. Since the supervisor is a system-generated user, I don’t see any way to change the supervisor’s locale.

So my hunch is that all Node-RED add-ons have locale ‘en-US’.

As I also have Node-RED running independently on Raspberry Pi, I can cross check this. For my Raspberry Pi I have to set the timezone myself using TZ as a system/flow environment variable. As my Node-RED is a simple program on the PI, without a docker container, the locale appear to be correctly coming from the system settings (which I set for the Pi) so I have

{
  locale: 'en-GB',
  calendar: 'gregory',
  numberingSystem: 'latn',
  timeZone: 'Europe/London',
  year: 'numeric',
  month: '2-digit',
  day: '2-digit'
}

What I had never noticed until this morning is that this actually makes a difference. I have always used “short” for the month, since my HA Node-RED by default shows (HA WebSocket) node status as “01/12/26”, and I changed this early on to show Jan as the month.

Looking at my HA Node-RED add-onJan 12

Looking at my Raspberry Pi Node-RED12 Jan

so yes, it is not working.

I wonder if there is a way to set/override the locale for the Node-RED add-on docker?

Add:

I have used the moment node (date time formatter) quite a lot, and the UI config defaults the timezones from the ‘system’, and offers locale formatting, by default as ‘C’ for local computer system.

A quick test shows that, although Node-RED add-on knows my timezone, the system locale is still stuck as the default en-US, and I have to set the locale manually in the node to en-GB to get the UK format.

1 Like

I don’t currently have an add-on instance running, but in your add-on’s settings file you can try explicitly setting the locale by defining LANG:

process.env.LANG = "en-GB";
1 Like

So.
A bit more digging. I have used process.env to list the NR as add-on’s environment variables.

LANG: "C.UTF-8", so the add-on is normally set to lift the default “C” machine locale. Running on HA Blue, I have no idea how to go about setting the default locales at the machine level.

Adding

process.env.LANG = "en_GB";

at the top of the add-on settings.js file does indeed modify the environment LANG.

The env variable is now “en_GB”

The exec command now returns

{
  locale: 'en-GB',
  calendar: 'gregory',
  numberingSystem: 'latn',
  timeZone: 'Europe/London',
  year: 'numeric',
  month: '2-digit',
  day: '2-digit'
}

However, the add-on instance still returns a node status with Jan 12 as month-day. I can only assume that the default “C” is still taking precedence over the LANG variable.

1 Like