Feel like idiot: how to add date-time to notification message in JSON format

I’ve tried several options, but I’m totally confused…
Using NODE-RED and in 1 workflow I want to:

  1. Capture current date+time
  2. Send a message using Notification service where in the text the current date+time is inserted

Now item 1 I have, my debug tells me the following:

*17/03/2024, 16:48:46[node: debug 1] *
msg.outTz : string[30]

“Sunday, March 17th 2024, 16:00”

For item 2 I’m using the data field in JSON format (see picture - here empty)

Can someone show me a sample please?

Much appreciated!

I’ve always had trouble with timestamps using $now or $millies when trying to deal with dst. I recently realized I have moment available. I think this is because I installed the moment node in the palette manager. Using "lll" returns the local time and date in the format

image

{
   "message": $moment().format("lll"),
   "title": "My Title"   
}

I made this at one point to understand the date-time features in node red.
It is just a couple of inject nodes and a function node with all kind of different ways to output date and time and that is then shown in a debug node.

[{"id":"14e1afbde9a425e9","type":"inject","z":"be03f9025a1f137a","name":"test (US)","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":555,"wires":[["86a4d3f3dbd3b494"]]},{"id":"fee8ca78ceac8578","type":"debug","z":"be03f9025a1f137a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":605,"y":525,"wires":[]},{"id":"86a4d3f3dbd3b494","type":"function","z":"be03f9025a1f137a","name":"DateTime","func":"// msg.language is the language code in the form xx-YY. \n// Most of the language codes from here should work: http://www.lingoes.net/en/translator/langcode.htm\n// If no msg.language code is selected, then en-US is default.\n//\n// msg.payload contain the date\n// The script will try to parse a human written datetime, like december 1, 2033 11:25 AM GMT+1\n// If this can not be passed correctly, then it will try to read it as a timestamp value instead\n// Timestamps from within Node-Red works perfectly, but timestamps coming from HA might be missing some digits,\n// so you need to add the missing zeros in the end by *10000 or whatever is missing to reach the same number\n// of digits as Node-Red timestamps.\n\n// more info on the date objects used: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date\n// more info on localization of datetime: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat\n\n\nif (!msg.language) { msg.language = 'en-US'}\nlet input = Date.parse(msg.payload);\nif (isNaN(input)) { input = msg.payload }\nlet dateobject = new Date(input)\n\nmsg.timevalue = dateobject.valueOf();\n\nmsg.datestring = new Intl.DateTimeFormat(msg.language, { dateStyle: 'full', timeStyle: 'full' }).format(dateobject);\nmsg.date = dateobject.getDate(); //\n\nmsg.month = new Intl.DateTimeFormat(msg.language, { month: 'numeric' }).format(dateobject);\nmsg.monthshort = new Intl.DateTimeFormat(msg.language, { month: 'short' }).format(dateobject);\nmsg.monthlong = new Intl.DateTimeFormat(msg.language, { month: 'long' }).format(dateobject);\n\nmsg.year = new Intl.DateTimeFormat(msg.language, { year: 'numeric' }).format(dateobject);\nmsg.year2 = new Intl.DateTimeFormat(msg.language, { year: '2-digit' }).format(dateobject);\n\nmsg.day = dateobject.getDay();\nmsg.dayshort = new Intl.DateTimeFormat(msg.language, { weekday: 'short' }).format(dateobject);\nmsg.daylong = new Intl.DateTimeFormat(msg.language, { weekday: 'long' }).format(dateobject);\n\nmsg.hour24 = new Intl.DateTimeFormat(msg.language, { hour: 'numeric', hour12: false }).format(dateobject);\nmsg.hour24_2 = new Intl.DateTimeFormat(msg.language, { hour: '2-digit', hour12: false }).format(dateobject);\nmsg.hour12 = new Intl.DateTimeFormat(msg.language, { hour: 'numeric', hour12: true }).format(dateobject).split(\" \")[0];\nmsg.hour12_2 = new Intl.DateTimeFormat(msg.language, { hour: '2-digit', hour12: true }).format(dateobject).split(\" \")[0];\nmsg.hour12prefix = new Intl.DateTimeFormat(msg.language, { hour: '2-digit', hour12: true }).format(dateobject).split(\" \")[1];\n\nmsg.minute = dateobject.getMinutes();\nmsg.minute2 = new Intl.DateTimeFormat(msg.language, { minute: '2-digit' }).format(dateobject);\n\nmsg.second = dateobject.getSeconds();\nmsg.second2 = new Intl.DateTimeFormat(msg.language, { second: '2-digit' }).format(dateobject);\n\nmsg.timezone = new Intl.DateTimeFormat('en-US', { timeZoneName: 'short' }).format(dateobject).split(\" \")[1];\n\nreturn msg;\n\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":525,"wires":[["fee8ca78ceac8578"]]},{"id":"eceb1ec5cdfe9e8b","type":"inject","z":"be03f9025a1f137a","name":"test (DK)","props":[{"p":"payload"},{"p":"language","v":"da","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1667081486000","payloadType":"num","x":240,"y":510,"wires":[["86a4d3f3dbd3b494"]]},{"id":"d650cc345d25be7a","type":"inject","z":"be03f9025a1f137a","name":"test (GB)","props":[{"p":"payload"},{"p":"language","v":"en-GB","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":600,"wires":[["86a4d3f3dbd3b494"]]},{"id":"dc1fdba9165a34c4","type":"inject","z":"be03f9025a1f137a","name":"test (DK)","props":[{"p":"payload"},{"p":"language","v":"da-DK","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"22. januar 2022 00:28","payloadType":"str","x":240,"y":465,"wires":[["86a4d3f3dbd3b494"]]}]