Date management & debug message curious behavior?

Hi there!

I try to play with Date() inside a function block and found something curious...non blocking, but I would be happy to understand.

I need a timestamp in millisecond style (a non formatted integer) so I can easily compare or do some processing.

at first I tried this:

var test = new Date();
msg.payload = test;
return msg;

And output this on a debug box.
debug windows shows:
payload: "2020-07-17T12:39:02.927Z"

The date is written in read a looks like a formatted text output, so I thought I may not be able to use this for comparison or operation, but just in case, I tried this:

var test = new Date();
msg.payload = test - 3600000;
return msg;

This time the debug windows shows a numeric payload, written in blue:
payload: 1594985920276
I can click on the blue value to see different format like:
payload: 2020-07-17T11:38:40.276Z

So it seems fine: I guess I can do what I need to do with my "test = new Date();".

But I wonder why it shows like a formatted string if I do not modify my value...?

Hi @waquete

When you do var test = new Date(), you are creating a new Date object. The Debug sidebar sees it is a Date object so displays it in a human readable format.

When you do test - 360000 you are converting the Date object to a number - so the Debug sidebar displays it as a number. But the sidebar is a bit smarter than that and recognises that whilst it is a number, it is within a range of values that could be a Date - so will display it as a Date if you click on it.

ahah this debug window is smarter than me :smile:

Thanks for explanation, it's crystal clear now!

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