Why was getting milliseconds system time removed in Godot 4.0

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Azengar

Hi all,

I might be missing something, but I noticed that commit ‘c6de387’ removed:

virtual uint64_t get_system_time_msecs() const;

From the OS class without providing alternatives.

The time related functions were later moved to the new Time class but still without any replacement.

Is there still a way to get the current system (or UTC) timestamp in milliseconds in GDScript? and if not why?

:bust_in_silhouette: Reply From: codelyok13

It seems to be there

Another way is:

var sys_time = get_unix_time_from_datetime_string(get_time_string_from_system())

Thanks for the answer!

int get_ticks_msec ( ) const

Does not seem to do what I want, as it returns the amount of time passed in milliseconds since the engine started, and not the system time.

I will have to try:

var sys_time = get_unix_time_from_datetime_string(get_time_string_from_system())

But since the documentation for get_time_string_from_system() says it returns the time in a HH:MM:SS, I guess the ms will be omitted.

Azengar | 2022-03-14 08:59

Yeah. I noticed I read you question wrong and it seems like the best you can get is

system_time_in_seconds - game_start_time_in_msecs to get close to the answer.

The only other way is to use the timer or make a proposal to get that feature added back into godot 4.0 since it still in alpha so it might not be to late to make a suggestion.

codelyok13 | 2022-03-14 15:20

I will make a proposal, thanks again. :slight_smile:

Azengar | 2022-03-14 18:16

Your welcome and let me know if there is anything I can do to help as one of the projects I am working on also requires get msecs to work properly at this point and I want to move to 4.0 once it is out of alpha.

codelyok13 | 2022-03-15 02:54

See above the answer I received on the Godot chat, hope this helps!

Azengar | 2022-03-15 11:28

:bust_in_silhouette: Reply From: Azengar

To answer my own question with the response I received on the Godot Chat.

It was removed in favor of OS.get_unix_time(), which now returns float, so you can get sub-second values from the fractional part, see godot#39189.

Concrete example:

var unix_time: float = Time.get_unix_time_from_system()
var unix_time_int: int = unix_time
var dt: Dictionary = Time.get_datetime_dict_from_unix_time(unix_time)
var ms: int = (unix_time - unix_time_int) * 1000.0
var str := "%s.%s.%s %s:%s:%s:%s" % [dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, ms]

Shows 2022.3.15 11:42:11:621.

That is nice to know but I still feel like they should have just kept them as shorthand since it was nice to have.

codelyok13 | 2022-03-16 03:34

Agreed, but at least it’s still possible without having to write a native script.

Azengar | 2022-03-16 13:05