Timestamp to current date and time?

Moment is very good at what it does, but as Julian has pointed out - it's a true heavyweight!

node-red-contrib-moment code size = 7MB
node-red-contrib-simpletime code size = 40KB
node-red-dashboard code size = 3.7MB
node-red-contrib-ramp-thermostat code size = 72KB

Thank you, Nick.
I ended up with simple function:

var now = new Date().toLocaleString("en-GB");
return {payload: now};
9 Likes

I've never been known as a lightweight that's for sure! :smile:

Thank you!

So I read this and couldn't seem to get it to populate this correctly.

msg.payload = {state:true,timestamp:1579362774639}

So the inbound message is a boolean 0 or 1 value without the "state:" for a ui_statetrail node.

I keep losing either the boolean or the timestamp.

Any suggestion here?

try msg.payload = {"state":true,"timestamp":1579362774639}

Tried that I need the timestamp to be now() and the state as the inbound boolean value

How about

msg.payload = {"state":msg.payload,"timestamp":Date.now()}

?

1 Like

Or, as I mentioned, if you need the timestamp in seconds rather than ms:

msg.payload = { 
    "state": msg.payload, 
    "timestamp": ( Date.now() / 1000 ) 
}
1 Like

Use $now('[D01].[M01].[Y0001] [H01]:[m01]:[s01]', '+0200'). Where +0200 is an offset of your time zone. This will result in something like this:
"06.07.2020 21:07:53"

Taken from here: Date/Time functions Ā· JSONata

5 Likes