Get nice Date-Format from Timeseries?

Hello,

I would like to fill my dashboard with daily values for 200 days.
The values have a timestamp in the ms-format 1579046400000.
Unfortunately this format is total unreadable for a bar chart and too long.

Is it possible to convert into a nice date-format like 20200224 ? or 200224 ?

BR

node-red-contrib-moment

I have this package installed but I do not get the expected output

I get the time as an integer from the previous node:

x.timestamp = parseInt(msg.payload.Timeseries);

what can I do to get a nice date format ?

I searched for a ms-format time and didn't find any information, what kind of timestamp is that? Is it epoch time?

its the format of the time in miliseconds: 1579046400000

let y =msg.payload.Timeseries;
let x = y / 1000;
let w = secondsToHms(x);

msg.payload = w;

node.status({fill:"blue",shape:"dot",text:msg.payload});

function secondsToHms(d) {
d = Number(d);
var h = Math.floor(d / 3600);
var m = Math.floor(d % 3600 / 60);
var s = Math.floor(d % 3600 % 60);

var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "";
var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "";
var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
return hDisplay + mDisplay + sDisplay; 

}

return msg;

that looks nice, but it's the DATE I am after, not the TIME :slight_smile:

oops, sorry about that

Works for me

unfortunately I cannot use this on my function output, because I get 200 values from an SQL database query and I get a timestamp and a value
when I use the Date/Time Formatter the value is gone afterwards
so I have to solve this with another function node

var myDate = msg.payload.Timeseries;;
var d = myDate.toGMTString();
node.status({fill:"green",shape:"ring",text:d});

return msg;

this get you a date in day date month year and then time, you can either research a little more the GMTString opitions or parse out the stuff you don't want

just a note: apparently the GMTString is deprecated use the toUTCSting instead of that.

F.Y.I. If you point the input and outvalues at the variables in msg.payload it won't get wiped out.

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