Format timestamp in $now() function inside JSONata Expression Editor

#1

Hello guys.

I'm starting to learn the things involved in Node Red, including JavaScript and JSON.
Today, using the JSONata Expression Editor in Change Node to define a message, I tried to put the optional parameters for the $now () function, according to JSONata documentation, in order to format the timestamp.

$now ('[H01]:[m01]:[s01]')

But I get the following error:
Invalid JSONata expression: The argument 1 of the "now" function does not match the signature of the function.

Does Node Red accept the optional parameters for functions listed in the JSONata documentation?

0 Likes

#2

What version of Node-RED are you using?

Node-RED 0.19.5 has JSONata 1.5.4
Node-RED 0.20.0-beta.4+ has JSONata 1.6.4

0 Likes

#3

@jhmluna, search this discussion for "JSONata timestamp", and you will find this thread. My comments and replies from @knolleary and @dceejay will answer your question.

0 Likes

#4

Just to share things, this is my (now) best solution.

msg.time = new Date().toLocaleString();
return msg;

in a function node.

0 Likes

#5

Hi there.

Is 0.19.5.

@drmibell After read the tread, I finally understand.
Thank you all.

0 Likes