# toLocaleString not working h24 - Italy

**URL:** <https://discourse.nodered.org/t/tolocalestring-not-working-h24-italy/13134>\
**Category:** General\
**Created:** [10 July 2019 23:02 UTC](https://discourse.nodered.org/t/tolocalestring-not-working-h24-italy/13134 "2019-07-10T23:02:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lupin\_III](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lupin_iii/32/67650_2.png) [@Lupin\_III](https://discourse.nodered.org/u/Lupin_III)\
**Post date:** [10 July 2019 23:02 UTC](https://discourse.nodered.org/t/tolocalestring-not-working-h24-italy/13134/1 "2019-07-10T23:02:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [11 July 2019 02:58 UTC](https://discourse.nodered.org/t/tolocalestring-not-working-h24-italy/13134/2 "2019-07-11T02:58:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 July 2019 08:20 UTC](https://discourse.nodered.org/t/tolocalestring-not-working-h24-italy/13134/3 "2019-07-11T08:20:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [11 July 2019 08:31 UTC](https://discourse.nodered.org/t/tolocalestring-not-working-h24-italy/13134/4 "2019-07-11T08:31:35Z")

</div>

For my Pi `.toLocaleString('it-IT', { hour12:false })`  
does seem to work  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/60f30803e28d53c1305f883495ed8a5f6c4b2f8f.png)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [11 July 2019 10:48 UTC](https://discourse.nodered.org/t/tolocalestring-not-working-h24-italy/13134/5 "2019-07-11T10:48:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [11 July 2019 12:08 UTC](https://discourse.nodered.org/t/tolocalestring-not-working-h24-italy/13134/6 "2019-07-11T12:08:41Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Lupin\_III](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lupin_iii/32/67650_2.png) [@Lupin\_III](https://discourse.nodered.org/u/Lupin_III)\
**Post date:** [15 July 2019 14:02 UTC](https://discourse.nodered.org/t/tolocalestring-not-working-h24-italy/13134/7 "2019-07-15T14:02:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fuerst](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fuerst/32/14165_2.png) [@fuerst](https://discourse.nodered.org/u/fuerst)\
**Post date:** [10 November 2019 17:29 UTC](https://discourse.nodered.org/t/tolocalestring-not-working-h24-italy/13134/8 "2019-11-10T17:29:37Z")

</div>

Full ICU support in standard NodeJS builds seems to be on it's way, see [https://github.com/nodejs/node/pull/29522](https://github.com/nodejs/node/pull/29522)

Meanwhile installing [https://www.npmjs.com/package/full-icu](https://www.npmjs.com/package/full-icu) adds the necessary _icudt64l.dat_ file. With this `Date.toLocaleString()` is working as expected.
