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

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

1692142072777 1692142072777

Therefore, this redundancy must be correctly described in the documentation.

Page URL: https://create.roblox.com/docs/reference/engine/datatypes/DateTime#UnixTimestampMillis

1 Like

DateTime.now() is a constructor for a DateTime object. When printed, the object gets serialized to it’s UnixTimestampMillis, similar to how printing a part serializes the part’s name into output. The datetime object is not equivalent to it’s UnixTimestampMillis, and neither is a part equivalent to it’s name.

I’m not sure what the redundancy is here, but there may be a case for serializing the log output for DateTime objects to not appear as a number. I know that this confused me early on when I was messing with them.

3 Likes

Did you notice that the two produce the same result?

One is a DateTime object and the other is a number. They just look the same in output.

print(typeof(DateTime.now()), typeof(DateTime.now().UnixTimestampMillis))

DateTime number

1 Like

Maybe I didn’t make myself clear about something very simple:
If I want to get the current timestamp with milliseconds, I can either use DateTime.now().UnixTimestampMillis or simply DateTime.now().
It is to this redundancy that I am referring.

DateTime.now() gives you a DateTime object which you can do other operations with. It will print it’s milliseconds when logged, but it is not equivalent to that number. These are not the same.

Is this redundant? The code I’ve written is redudnant, but the implementation is not.
print(workspace, workspace.Name)

Workspace Workspace

Is there a specific place in the documentation that is redundant? I’m not sure exactly what the issue is.

2 Likes

Sorry, you’re right.
I won’t be able to do math operations directly with DateTime.now(). For example:
print(DateTime.now()/1000) will produce:

attempt to perform arithmetic (div) on DateTime and number

So the correct thing is to use DateTime.now().UnixTimestampMillis.

However, since this has caused all this confusion, I will leave this topic open for the Roblox team to consider making this clearer in the current documentation.

Thanks.

1 Like

Howdy @rogeriodec_games!

Thanks for flagging this. I’ve drafted a small change to the references here to make this more clear in the future. This change is expected to land some time next week in our documentation update.

Appreciate you helping make our docs more clearer for our community! Have a great day :slight_smile:.

1 Like