toLocaleString not working h24 - Italy

Hi, I'm running node-red V0.20.6 on a raspberry pi 3 with stretch. My country is Italy.
I need to have date like "2019-07-11 22:15:36". For this I used in a function node the toLocaleString() command . Running the flow in a Windows PC with windows 10 it works perfectly, but on the raspberry it returns a 12h format, causing a lot of trouble within the flow. I even tryed to use the option like hour12:false or hourCycle:"h24" but it seems doesnt consider them and always returns a 12h format.
I've searched a lot and tried several approach but without success. Can you help me?
Thanks a lot

Did you try .toLocaleString('it-IT') ?

I seem to remember that there are some problems with 12/24 hr and toLocaleString in some versions of nodejs, though I can't find the reference at the moment. You might be better using an alternative such as the moment node.

For my Pi .toLocaleString('it-IT', { hour12:false })
does seem to work

Node does not include all the locale awareness by default. It has to be compiled into the node runtime at build time.

So passing a locale into toLocaleString won't work in node, but will in the browser.

This is why the moment library exists.

1 Like

Interesting - but yes if I use the above it works when run in a function node (ie the node.js server side) - it may well be ignoring the it-IT part but needs something there in order to then accept the hour12 option. (vs having to load the massive moment library)

Hi guys. Thanks a lot for your support. Yes, at the end it works as dceejay suggested, with .toLocaleString('it-IT', { hour12:false }).
Again thanks a lot

1 Like

Full ICU support in standard NodeJS builds seems to be on it's way, see

Meanwhile installing adds the necessary icudt64l.dat file. With this Date.toLocaleString() is working as expected.

1 Like