Simple date time question but i can not find answer

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"

Try node-red-contrib-moment

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.

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

solved it by using this

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));
1 Like

It is on the list :frowning:

Pull requests welcome! :slight_smile:

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.

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.

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