# Simple date time question but i can not find answer

**URL:** <https://discourse.nodered.org/t/simple-date-time-question-but-i-can-not-find-answer/22762>\
**Category:** General\
**Created:** [7 March 2020 14:52 UTC](https://discourse.nodered.org/t/simple-date-time-question-but-i-can-not-find-answer/22762 "2020-03-07T14:52:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![GravityRZ](https://avatars.discourse-cdn.com/v4/letter/g/839c29/32.png) [@GravityRZ](https://discourse.nodered.org/u/GravityRZ)\
**Post date:** [7 March 2020 14:52 UTC](https://discourse.nodered.org/t/simple-date-time-question-but-i-can-not-find-answer/22762/1 "2020-03-07T14:52:38Z")

</div>

i am trying to get an european date and time.

time is no problem but the date still keeps the format of mm/dd/yyyy despite the fact that i am using nl-NL  
as a matter of fact i can try any locale but the date keeps the same format.

var date = new Date().toLocaleString('nl-NL')

"3/7/2020, 3:47:30 PM"

what would be the code(if it exists) to get this output(without using nodes)  
"7/3/2020, 15:47:30"

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [7 March 2020 15:09 UTC](https://discourse.nodered.org/t/simple-date-time-question-but-i-can-not-find-answer/22762/2 "2020-03-07T15:09:03Z")

</div>

Try [node-red-contrib-moment](https://flows.nodered.org/node/node-red-contrib-moment)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [7 March 2020 15:14 UTC](https://discourse.nodered.org/t/simple-date-time-question-but-i-can-not-find-answer/22762/3 "2020-03-07T15:14:40Z")

</div>

The Locale feature in JavaScript is dependent on a set of locale files and Node.JS doesn't load them all by default I don't think (they are quite large). So possibly, you are hitting that problem.

In any case, personally I find the most reliable format to be "YYYY-MM-DD HH:mm:ss" which is an ISO format that also sorts correctly as a string. I always set my desktop/laptop devices, Excel, etc. to use that format. It is far less confusing.

As Paul says, you could also use the moment node which can also do timezone changes and simple date math as well. It uses MomentJS and so has it's own timezone/locale data.

---

<div class="post-metadata">

**Author:** ![GravityRZ](https://avatars.discourse-cdn.com/v4/letter/g/839c29/32.png) [@GravityRZ](https://discourse.nodered.org/u/GravityRZ)\
**Post date:** [7 March 2020 15:42 UTC](https://discourse.nodered.org/t/simple-date-time-question-but-i-can-not-find-answer/22762/4 "2020-03-07T15:42:41Z")

</div>

tried moment but for a dedicated node i expected it to be much more complete.

e.g when you can input a format it would be nice to have a drop down list with formats or at least a list of formats in the readme.

i did some trail and error and found a usable format (and a BUG)

MM-DD-YY hh:mm:ss gives "07-03-20 04:40:19

DD-MM-YY hh:mm:ss gives "03-07-20 04:40:19

i guess people coding stuff really do not like the euroipean format.

i have used locale nl-NL which really needs to be in the format DD-MM-YY

---

<div class="post-metadata">

**Author:** ![GravityRZ](https://avatars.discourse-cdn.com/v4/letter/g/839c29/32.png) [@GravityRZ](https://discourse.nodered.org/u/GravityRZ)\
**Post date:** [7 March 2020 16:54 UTC](https://discourse.nodered.org/t/simple-date-time-question-but-i-can-not-find-answer/22762/5 "2020-03-07T16:54:11Z")

</div>

solved it by using this

```auto
var date;
date = new Date();
date = (('00' + date.getDate()).slice(-2)+'-'+('00' + (date.getMonth()+1)).slice(-2) + '-' + date.getFullYear() + ' ' + ('00' + date.getHours()).slice(-2) + ':' + ('00' + date.getMinutes()).slice(-2) + ':' + ('00' + date.getSeconds()).slice(-2));

```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [7 March 2020 17:10 UTC](https://discourse.nodered.org/t/simple-date-time-question-but-i-can-not-find-answer/22762/6 "2020-03-07T17:10:28Z")

</div>

> [@GravityRZ](#):
>
> tried moment but for a dedicated node i expected it to be much more complete.
> 
> e.g when you can input a format it would be nice to have a drop down list with formats or at least a list of formats in the readme.

It is on the list ☹

Pull requests welcome! 🙂

Like many things, it is started in my development code - creating an API that will return the full list or a partial list based on selecting a country.

But nobody else - nor yourself - have asked so it has not been on the priority list.

---

<div class="post-metadata">

**Author:** ![GravityRZ](https://avatars.discourse-cdn.com/v4/letter/g/839c29/32.png) [@GravityRZ](https://discourse.nodered.org/u/GravityRZ)\
**Post date:** [7 March 2020 17:32 UTC](https://discourse.nodered.org/t/simple-date-time-question-but-i-can-not-find-answer/22762/7 "2020-03-07T17:32:37Z")

</div>

thanks. just found out that this was not working as expected that is why i did not mention it.

my workaround however(not my code) seems to work really well and only adds 2 extra lines of code to a function node.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 March 2020 17:46 UTC](https://discourse.nodered.org/t/simple-date-time-question-but-i-can-not-find-answer/22762/8 "2020-03-21T17:46:01Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
