DateTime.now() and DateTime.now().UnixTimestampMillis seems to be the same thing

print(DateTime.now(), DateTime.now().UnixTimestampMillis) will print the same timestamp with miliseconds:

1692142072777 1692142072777

Is this correct?

1 Like

This is because fromUnixTimestampMillis returns a new DateTime object from the given Unix timestamp, or the number of milliseconds since January 1st, 1970 at 00:00 (UTC).

So yes, what is printed is the number of milliseconds since January 1st, 1970 at 00:00 (UTC).

2 Likes

Yes, DateTime.now() when printed will return the time with Milliseconds just like .UnixTimestampMillis, you would be looking for .UnixTimestamp if you want the alternate version without Milliseconds.

1692144251224 -- DateTime.now()
1692144251    -- UnixTimestamp
1692144251224 -- UnixTimestampMillis
2 Likes

@paetemc2 @DasKairo
Thanks, but I just found out around here that although visually the results are the same, I won’t be able to do math operations directly with DateTime.now(), since it’s an object and not a number.

1 Like

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