How to get current system time

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By carbajosa
:warning: Old Version Published before Godot 3 was released.

Hi, I am new to GDScript. Been trying to look at the API but I don’t seem to find anything related to date and time. How do I get the system time?

:bust_in_silhouette: Reply From: kubecz3k

OS.get_time() returns dictionary with three values: hour, minute and second
example:

var timeDict = OS.get_time();
var hour = timeDict.hour;
var minute = timeDict.minute;
var seconds = timeDict.second;

Thanks! This is exactly what I’m looking for :slight_smile:

carbajosa | 2016-04-20 18:33

no problem :slight_smile:

kubecz3k | 2016-04-20 18:35

is it limited only up to the hour? or can we also get the date of the current time?

Numshv | 2022-10-07 16:50

:bust_in_silhouette: Reply From: george12teodor

Here is a method to get it in a more curated form

`:

var time = OS.get_time()
var time_return = String(time.hour) +":"+String(time.minute)+":"+String(time.second)
:bust_in_silhouette: Reply From: brooswit

I had a similar question. I needed the unix timestamp in milliseconds. This function was what I was looking for: OS — Godot Engine (stable) documentation in English

:bust_in_silhouette: Reply From: Luminn

OS.get_time() was deprecated in the latest versions of Godot 3 and was removed from Godot 4.

In both Godot 3 and Godot 4, you can use the singleton Time for this task:

  • Time.get_time_dict_from_system() to get a dictionary with hour, minute, and second (same behavior as the old OS.get_time()).
  • Time.get_time_string_from_system() can be used to get a preformatted string in the format HH:MM:SS.

And Time.get_datetime_string_from_system() if you want to include date, the format is YYYY-MM-DDTHH:MM:SS.

wdv4758h | 2022-10-25 15:43