+3 votes

I've been googling this for a while, and I'm trying to create a tcp latency logger. But having trouble because I need to get the time difference in milliseconds not just seconds:

I found these:

OS.get_system_time_secs

and

OS.get_unix_time

but seems like there is no millisecond method available yet? I'm looking over the docs now :D

in Engine by (313 points)

1 Answer

+7 votes
Best answer

Looks like I found something that will work: OS.get_ticks_msec()

Edit: Yep, this works! Awesome, sorry guys I was just getting worried

by (313 points)

But this returns only elapsed milliseconds after app starts.
It's not exactly unix millisecond timestamp which I need for sometimes.
I think It would be added 3.0

Be that as it may, this is certainly better than using something like OS.get_timestamp, which returns a dictionary of sub-components (hours, minutes, etc.) which is not easy to compare.

Based on this, you can get milliseconds by doing

OS.get_ticks_msec() % 1000

It should return a value of 0 - 999
but I'm not sure if this is the actual milliseconds or this is dependent on something else. Hope someone can affirm this is milliseconds.

Cons to this method of getting milliseconds is that you are basically asking the computer to do more math whenever you run this line. hope there will be one command to get milliseconds on godot 4.0

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.