Light weight library free time-date-string-functions (hour, min, sec, day, month with leading 0)

[{"id":"7a8f4d515c569ef4","type":"group","z":"93d94ffa17becd25","name":"light weight library free time-date-string-functions (hour, min, sec, day, month with leading 0)","style":{"fill":"#ffefbf","fill-opacity":"0.18","label":true},"nodes":["9349197e3ec3c38c","a5d5a1231ebcadad","2e5a1059caa7ef3f","d9fb9044a7fc6a11","bfb14c881c262fc7","9ce7f0169a0680a1","dd252713d82813ec","ed3b13bb082cccfa","7699a7d4d69b4430","179de3c0ebc7f694","afc0fb0cc7757c97","cef33a6d671c3fb0","3270715a84e162ca","222f95b48ab65c83","35ef29af4074f9d5","018865504fb5dbd6","913ab0a902d8c5d4","9a5300c29e8af76b"],"x":114,"y":39,"w":652,"h":382},{"id":"9349197e3ec3c38c","type":"function","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"hh:mm:ss","func":"msg.payload = date_time_string(msg.payload);\nnode.status({ fill: \"red\", shape: \"dot\", text: msg.payload });\nreturn msg;\n\nfunction date_time_string(timestamp){\n    let text = new Date(timestamp).toLocaleTimeString();\n    let text_a = text.split(':');\n    const hours = (\"0\" + text_a[0]).slice(-2);\n    const minutes = (\"0\" + text_a[1]).slice(-2);\n    const seconds = (\"0\" + text_a[2]).slice(-2);    \n    return ( hours + ':' + minutes + ':' + seconds ); \n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":140,"wires":[["2e5a1059caa7ef3f"]]},{"id":"a5d5a1231ebcadad","type":"inject","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":140,"wires":[["9349197e3ec3c38c"]]},{"id":"2e5a1059caa7ef3f","type":"debug","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"debug 2527","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":140,"wires":[]},{"id":"d9fb9044a7fc6a11","type":"function","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"DD.MM.YYYY","func":"msg.payload = date_string(msg.payload);\nnode.status({ fill: \"red\", shape: \"dot\", text: msg.payload });\nreturn msg;\n\n\nfunction date_string(timestamp){\n    let text_a = new Date(msg.payload).toLocaleDateString();\n    text_a = text_a.split('.');\n    const day = (\"0\" + text_a[0]).slice(-2);\n    const month = (\"0\" + text_a[1]).slice(-2);\n    const year = text_a[2];    \n    return ( day + '.' + month + '.' + year ); \n}\n\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":200,"wires":[["9ce7f0169a0680a1"]]},{"id":"bfb14c881c262fc7","type":"inject","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":200,"wires":[["d9fb9044a7fc6a11"]]},{"id":"9ce7f0169a0680a1","type":"debug","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"debug 2528","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":200,"wires":[]},{"id":"dd252713d82813ec","type":"function","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"hh:mm:ss DD.MM.YYYY","func":"const x = time_date_string(msg.payload);\nnode.status({ fill: \"red\", shape: \"dot\", text: x});\nreturn{payload:x};\n\nfunction time_date_string(time) {\n    let x = new Date(time).toLocaleString();\n    x = x.split(',');\n\n    let d = x[0].trim();\n    d = d.split('.');\n    const day = (\"0\" + d[0]).slice(-2);\n    const month = (\"0\" + d[1]).slice(-2);\n    const year = d[2];\n\n    let t = x[1].trim();\n    t = t.split(':');\n    const hours = (\"0\" + t[0]).slice(-2);\n    const minutes = (\"0\" + t[1]).slice(-2);\n    const seconds = (\"0\" + t[2]).slice(-2); \n\n    return (hours + ':' + minutes + ':' + seconds + \" \" + day + '.' + month + '.' + year);\n    //return (day + '.' + month + '.' + year + \" \" + hours + ':' + minutes + ':' + seconds);     \n} ","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":260,"wires":[["7699a7d4d69b4430"]]},{"id":"ed3b13bb082cccfa","type":"inject","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":260,"wires":[["dd252713d82813ec"]]},{"id":"7699a7d4d69b4430","type":"debug","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"debug 2533","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":260,"wires":[]},{"id":"179de3c0ebc7f694","type":"function","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"hh:mm","func":"msg.payload = date_time_string(msg.payload);\nnode.status({ fill: \"red\", shape: \"dot\", text: msg.payload });\nreturn msg;\n\nfunction date_time_string(timestamp){\n    let text = new Date(timestamp).toLocaleTimeString();\n    let text_a = text.split(':');\n    const hours = (\"0\" + text_a[0]).slice(-2);\n    const minutes = (\"0\" + text_a[1]).slice(-2);\n    return ( hours + ':' + minutes); \n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":80,"wires":[["cef33a6d671c3fb0"]]},{"id":"afc0fb0cc7757c97","type":"inject","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":80,"wires":[["179de3c0ebc7f694"]]},{"id":"cef33a6d671c3fb0","type":"debug","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"debug 2537","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":80,"wires":[]},{"id":"3270715a84e162ca","type":"inject","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":320,"wires":[["222f95b48ab65c83"]]},{"id":"222f95b48ab65c83","type":"function","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"format based time strings","func":"const x = time_date_string(msg.payload, \"HH:MM:SS @ DD-MM-YYYY\");\nnode.status({ fill: \"red\", shape: \"dot\", text: x});\nreturn{payload:x};\n\nfunction time_date_string(time, format) {\n    let x = new Date(time).toLocaleString();\n    x = x.split(',');\n\n    let d = x[0].trim();\n    d = d.split('.');\n    const day = (\"0\" + d[0]).slice(-2);\n    const month = (\"0\" + d[1]).slice(-2);\n    const year = d[2];\n\n    let t = x[1].trim();\n    t = t.split(':');\n    const hours = (\"0\" + t[0]).slice(-2);\n    const minutes = (\"0\" + t[1]).slice(-2);\n    const seconds = (\"0\" + t[2]).slice(-2); \n\n    switch (format){ \n        case \"HH:MM:SS @ DD-MM-YYYY\":\n            return (hours + ':' + minutes + ':' + seconds + \" @ \" + day + \"-\" + month + \"-\" + year);\n        case \"HH:MM:SS DD-MM-YYYY\":\n            return (hours + ':' + minutes + ':' + seconds + \" \" + day + \"-\" + month + \"-\" + year);\n        case \"DD-MM-YYYY\":\n            return (day + \"-\" + month + \"-\" + year);\n        case \"HH:MM:SS\":\n            return (hours + ':' + minutes + ':' + seconds);\n        case \"HH:MM\":\n            return (hours + ':' + minutes);\n    }\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":320,"wires":[["35ef29af4074f9d5"]]},{"id":"35ef29af4074f9d5","type":"debug","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"debug 2538","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":320,"wires":[]},{"id":"018865504fb5dbd6","type":"function","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"runtime input ms","func":"msg.payload = runtime_str(msg.payload);\nnode.status({ fill: \"red\", shape: \"dot\", text: msg.payload });\nreturn msg;\n\nfunction runtime_str(ms) {\n    const t = ms / 1000;\n    const h = (Math.floor(t / 3600)).toString();\n    const m = (Math.floor(t % 3600 / 60)).toString();\n    const s = (Math.floor(t % 3600 % 60)).toString();\n    return (h + \":\" + (\"0\" + m).slice(-2) + \":\" + (\"0\" + s).slice(-2));\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":380,"wires":[["9a5300c29e8af76b"]]},{"id":"913ab0a902d8c5d4","type":"inject","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"86400000","payloadType":"num","x":220,"y":380,"wires":[["018865504fb5dbd6"]]},{"id":"9a5300c29e8af76b","type":"debug","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"debug 2539","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":380,"wires":[]}]
1 Like

Hi,

Thanks for the share.

I only took a very quick look at this - I see you use toLocalexxx then split the parts out of the date string. Your code relied on the assumption that the date format would always be DD.MM.YYYY however, in some locales, the date format might be MM/DD/YYYY or YYYY-MM-DD.

For example, one of your original functions was like this:

const x = time_date_string(msg.payload);
node.status({ fill: "red", shape: "dot", text: x});
return{payload:x};

function time_date_string(time) {
    let x = new Date(time).toLocaleString();
    x = x.split(',');

    let d = x[0].trim();
    d = d.split('.');
    const day = ("0" + d[0]).slice(-2);
    const month = ("0" + d[1]).slice(-2);
    const year = d[2];

    let t = x[1].trim();
    t = t.split(':');
    const hours = ("0" + t[0]).slice(-2);
    const minutes = ("0" + t[1]).slice(-2);
    const seconds = ("0" + t[2]).slice(-2);

    return (hours + ':' + minutes + ':' + seconds + " " + day + '.' + month + '.' + year);
}

A more globally correct approach would be to use the built in date functions (like getHour) to get the parts of the date-time, then re-assemble them to your desired format e.g...

const x = formatDateTime(msg.payload);
node.status({ fill: "red", shape: "dot", text: x });
return { payload: x };

function formatDateTime(timestamp) {
  const date = new Date(timestamp);

  // Get date and time components with zero-padding
  const day = date.getDate().toString().padStart(2, '0');
  const month = (date.getMonth() + 1).toString().padStart(2, '0');
  const year = date.getFullYear().toString();
  const hours = date.getHours().toString().padStart(2, '0');
  const minutes = date.getMinutes().toString().padStart(2, '0');
  const seconds = date.getSeconds().toString().padStart(2, '0');

  // Assemble the formatted string using template literals
  return `${hours}:${minutes}:${seconds} ${day}.${month}.${year}`;
}

Of course, you could use the built in moment package in a change node, or import date-fns in a function node to avoid all of the reinventing of the wheel.

2 Likes

Hi Steve,

first, I wanted to avoid moment.
second, yes, I have these functions working.
I just played with to localexxx and thought I could use the old approach with day month etc.

function date_time_string(timestamp){
    const date = new Date(timestamp);
    const year = date.getFullYear();
    const month = ("0" + (date.getMonth() + 1)).slice(-2);
    const day = ("0" + date.getDate()).slice(-2);
    const hours = ("0" + date.getHours()).slice(-2);
    const minutes = ("0" + date.getMinutes()).slice(-2);
    const seconds = ("0" + date.getSeconds()).slice(-2);
    return ( day + "-" + month + "-" + year + " " + hours + ':' + minutes + ':' + seconds ); 
}

but I like your padstart :slightly_smiling_face:

or dayjs which is somewhat compatible with moment.
a 'library' means it has multiple functions, this 'library' has only one function and it is not flexible. To start, what if you don't want a padded 0 ?

based on Steve's input I rewrote the functions.
easy to copy them into your own function nodes

[{"id":"7a8f4d515c569ef4","type":"group","z":"93d94ffa17becd25","name":"light weight library free time-date-string-functions (hour, min, sec with leading 0)","style":{"fill":"#ffefbf","fill-opacity":"0.18","label":true},"nodes":["9349197e3ec3c38c","a5d5a1231ebcadad","2e5a1059caa7ef3f","d9fb9044a7fc6a11","bfb14c881c262fc7","9ce7f0169a0680a1","dd252713d82813ec","ed3b13bb082cccfa","7699a7d4d69b4430","179de3c0ebc7f694","afc0fb0cc7757c97","cef33a6d671c3fb0","3270715a84e162ca","222f95b48ab65c83","35ef29af4074f9d5","018865504fb5dbd6","913ab0a902d8c5d4","9a5300c29e8af76b"],"x":114,"y":39,"w":652,"h":382},{"id":"9349197e3ec3c38c","type":"function","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"hh:mm:ss","func":"msg.payload = formatDateTime(msg.payload);\nnode.status({ fill: \"red\", shape: \"dot\", text: msg.payload });\nreturn msg;\n\nfunction formatDateTime(timestamp) {\n  const date = new Date(timestamp);\n  const hours = date.getHours().toString().padStart(2, '0');\n  const minutes = date.getMinutes().toString().padStart(2, '0');\n  const seconds = date.getSeconds().toString().padStart(2, '0');\n  return `${hours}:${minutes}:${seconds}`;\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":140,"wires":[["2e5a1059caa7ef3f"]]},{"id":"a5d5a1231ebcadad","type":"inject","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":140,"wires":[["9349197e3ec3c38c"]]},{"id":"2e5a1059caa7ef3f","type":"debug","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"debug 2527","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":140,"wires":[]},{"id":"d9fb9044a7fc6a11","type":"function","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"DD.MM.YYYY","func":"msg.payload = formatDate(msg.payload);\nnode.status({ fill: \"red\", shape: \"dot\", text: msg.payload });\nreturn msg;\n\nfunction formatDate(timestamp) {\n  const date = new Date(timestamp);\n  const day = date.getDate().toString().padStart(2, '0');\n  const month = (date.getMonth() + 1).toString().padStart(2, '0');\n  const year = date.getFullYear().toString();\n  return `${day}.${month}.${year}`;\n}\n\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":200,"wires":[["9ce7f0169a0680a1"]]},{"id":"bfb14c881c262fc7","type":"inject","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":200,"wires":[["d9fb9044a7fc6a11"]]},{"id":"9ce7f0169a0680a1","type":"debug","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"debug 2528","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":200,"wires":[]},{"id":"dd252713d82813ec","type":"function","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"hh:mm:ss DD.MM.YYYY","func":"const t_d = time_date_string(msg.payload);\nnode.status({ fill: \"red\", shape: \"dot\", text:t_d});\nreturn{payload:t_d};\n\nfunction time_date_string(time_date) {\n  const date = new Date(time_date);\n  const day = date.getDate().toString().padStart(2, '0');\n  const month = (date.getMonth() + 1).toString().padStart(2, '0');\n  const year = date.getFullYear().toString();\n  const hours = date.getHours().toString().padStart(2, '0');\n  const minutes = date.getMinutes().toString().padStart(2, '0');\n  const seconds = date.getSeconds().toString().padStart(2, '0');\n  return `${hours}:${minutes}:${seconds} ${day}.${month}.${year}`;\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":260,"wires":[["7699a7d4d69b4430"]]},{"id":"ed3b13bb082cccfa","type":"inject","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":260,"wires":[["dd252713d82813ec"]]},{"id":"7699a7d4d69b4430","type":"debug","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"debug 2533","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":260,"wires":[]},{"id":"179de3c0ebc7f694","type":"function","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"hh:mm","func":"msg.payload = formatDateTime(msg.payload);\nnode.status({ fill: \"red\", shape: \"dot\", text: msg.payload });\nreturn msg;\n\nfunction formatDateTime(timestamp) {\n  const date = new Date(timestamp);\n  const hours = date.getHours().toString().padStart(2, '0');\n  const minutes = date.getMinutes().toString().padStart(2, '0');\n  return `${hours}:${minutes}`;\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":80,"wires":[["cef33a6d671c3fb0"]]},{"id":"afc0fb0cc7757c97","type":"inject","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":80,"wires":[["179de3c0ebc7f694"]]},{"id":"cef33a6d671c3fb0","type":"debug","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"debug 2537","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":80,"wires":[]},{"id":"3270715a84e162ca","type":"inject","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":320,"wires":[["222f95b48ab65c83"]]},{"id":"222f95b48ab65c83","type":"function","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"format based time strings","func":"const x = time_date_string(msg.payload, \"HH:MM:SS @ DD-MM-YYYY\");\nnode.status({ fill: \"red\", shape: \"dot\", text: x});\nreturn{payload:x};\n\nfunction time_date_string(time_date,format) {\n    const date = new Date(time_date);\n    const day = date.getDate().toString().padStart(2, '0');\n    const month = (date.getMonth() + 1).toString().padStart(2, '0');\n    const year = date.getFullYear().toString();\n    const hours = date.getHours().toString().padStart(2, '0');\n    const minutes = date.getMinutes().toString().padStart(2, '0');\n    const seconds = date.getSeconds().toString().padStart(2, '0');\n\n    switch (format){ \n        case \"HH:MM:SS @ DD-MM-YYYY\":\n            return `${hours}:${minutes}:${seconds}${\" @ \"}${day}.${month}.${year}`;\n        case \"HH:MM:SS DD.MM.YYYY\":\n            return `${hours}:${minutes}:${seconds} ${day}.${month}.${year}`;\n        case \"DD.MM.YYYY\":\n            return `${day}.${month}.${year}`;\n        case \"HH:MM:SS\":\n            return `${hours}:${minutes}:${seconds}`;\n        case \"HH:MM\":\n            return `${hours}:${minutes}`;\n    }\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":320,"wires":[["35ef29af4074f9d5"]]},{"id":"35ef29af4074f9d5","type":"debug","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"debug 2538","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":320,"wires":[]},{"id":"018865504fb5dbd6","type":"function","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"runtime input ms","func":"msg.payload = runtime_str(msg.payload);\nnode.status({ fill: \"red\", shape: \"dot\", text: msg.payload });\nreturn msg;\n\nfunction runtime_str(ms) {\n    const t = ms / 1000;\n    const h = (Math.floor(t / 3600)).toString();\n    const m = (Math.floor(t % 3600 / 60)).toString().padStart(2, '0');\n    const s = (Math.floor(t % 3600 % 60)).toString().padStart(2, '0');\n    return `${h}:${m}:${s}`;\n}            ","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":380,"wires":[["9a5300c29e8af76b"]]},{"id":"913ab0a902d8c5d4","type":"inject","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"86300000","payloadType":"num","x":220,"y":380,"wires":[["018865504fb5dbd6"]]},{"id":"9a5300c29e8af76b","type":"debug","z":"93d94ffa17becd25","g":"7a8f4d515c569ef4","name":"debug 2539","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":380,"wires":[]}]

Or of course use node-red-contrib-simpletime ...

2 Likes

Is there a reason not to use moment in a function node?

I cant remember if moment is actually available in a function node - you might need to import it on the setup tab.

But since it is available in the change node out of the box (using JSONata) I don't bother with function node.

In fact I rarely do any date formatting!

1 Like

Moment.js is a legacy project, now in maintenance mode.
If you check moment's npm page even they recommend;

In most cases, you should choose a different library.

So maybe not a great choice to use it anywhere in a new project.

What does this mean in terms of nodered? I often use moment when I have to process a timestamp. Did I missed in terms of timestamp processing other than jsonata? Is there any plan to remove/replace moment in NR?

All I know is... JSONata : $moment -> $dayjs - #16 by dceejay

1 Like