How to get time in milliseconds/milliseconds timestamp in gdscript?

Godot Version

4.1.3

Question

So, is there no more a way to get a timestamp in milliseconds?

In this thread → How to get milliseconds timestamp in gdscript the last know working method in Godot ?3? was this:

OS.get_system_time_msecs()

Which was kinda replaced in Godot 4.0 with:

Time.get_ticks_msec()

Which is the time in milliseconds since the start of the engine.

The Time class documentation Time — Godot Engine (stable) documentation in English doesn’t mention any other relevant methods.

There is also this related issue on Github (link is splitted since new users can’t post more than 2 links on the first post) HTTPS COLON SLASH SLASH github DOT com PATH /godotengine/godot/issues/19636

I wonder, does anyone know of a way to get the actual OS timestamp in milliseconds in the latest Godot?

Maybe this is what you are looking for:

Time.get_unix_time_from_system()

It returns seconds but the value is a float number, so it should be simple to convert to milliseconds.

Silly me!
At the very end of the documentation, there is written:

Note: Unlike other methods that use integer timestamps, this method returns the timestamp as a float for sub-second precision.

Yes, this is exactly the solution!

To get milliseconds one must therefore simply multiply by 1000:

var current_timestamp = Time.get_unix_time_from_system()
print(current_timestamp)
var current_timestamp_in_milliseconds = current_timestamp*1000
print(current_timestamp_in_milliseconds)

Output:

Timestamp is:
1708369184.09893
Milliseconds are:
1708369184098.93

Hopefully this thread can help other internauts.

Thanks @FencerDevLog !

Marking as solved

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