Timestamp to DOpus Date object

Happy holidays.
Given a timestamp in seconds, I can convert it using a Jscript Date():

var timestamp = 1642354317;
var date1= new Date(timestamp*1000);
DOpus.Output(date1);

Not what I wanted though. So for easy formatting, I tried to convert the same timestamp to a DOpus Date object, with no success. I tried using:

var date2 = DOpus.Create().Date(timestamp);
DOpus.Output(date2.Format());

var date2 = DOpus.Create().Date(date1);
DOpus.Output(date2.Format());

var date2 = DOpus.Create().Date();
date2.Set(timestamp); //gives error
DOpus.Output(date2.Format());

The only way I managed to do it is :

var date2 = DOpus.Create().Date('1970-01-01');
date2.Add(timestamp,'s');
DOpus.Output(date2.Format());

I wonder if there's an easier and single-line way? Or what I'm doing wrong?
Thanks.

The Date.Set method is probably what you want, if the timestamp is Unix epoch time. (On the Opus object, not the JS one.)

Thanks. But d oing that gives an error.

Also the manual states that I should be able to create it either using the timestamp (is a valid UTC timestamp, that I got it from the VirusTotal API report) or a JScript Date object, but neither gives the correct date.

Looks like this was left out of the docs (although mentioned in the release notes for 13.2.1); use the SetTime() method to set the timestamp using the epoch time in milliseconds (so multiply by 1000 to use a unix epoch timestamp). Works the same as the JScript Date.SetTime and Date.GetTime methods.

1 Like

Gives me an incorrect date :

SetTime, not Set.

Ah yes, sorry, I misread that part :smile: