How to get the current date and time in Godot 4: the Time singleton

By Eduardo Orellana · Updated

Time.get_datetime_dict_from_system() returns the local date and time as a Dictionary (year, month, day, weekday, hour, minute, second), and Time.get_datetime_string_from_system() as text. Godot 3's OS.get_datetime() is gone: it fails to parse with Static function "get_datetime()" not found in base "GDScriptNativeClass".

AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.

Intel or AMD Chromebook, with Linux turned on.

Download for macOSDownload for Windows

What Godot is checking

Godot 4 moved the clock off OS into the Time singleton. get_unix_time_from_system() gives seconds since 1970, get_ticks_msec() milliseconds since the engine started, for measuring durations.

The fix converts a fixed Unix time, so its output is the same on every run; the system calls take no argument and return the current moment.

Reproduce it

A Godot 3 clock call, in a Godot 4 project.

extends Node

func _ready():
	print(OS.get_datetime())

What Godot 4.7.2 prints

Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

SCRIPT ERROR: Parse Error: Static function "get_datetime()" not found in base "GDScriptNativeClass".
   at: GDScript::reload (res://answers/how-to-get-the-current-date-and-time-in-godot-4/repro.gd:4)
ERROR: Failed to load script "res://answers/how-to-get-the-current-date-and-time-in-godot-4/repro.gd" with error "Parse error".
   at: load (modules/gdscript/gdscript_resource_format.cpp:46)

Fix it

The same Dictionary and text for a fixed moment, and the keys the system call returns.

extends Node

func _ready() -> void:
	var moment := 1767225600
	print(Time.get_datetime_dict_from_unix_time(moment))
	print(Time.get_datetime_string_from_unix_time(moment))
	print(Time.get_datetime_dict_from_system().keys())

What the fixed script prints

Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

{ "year": 2026, "month": 1, "day": 1, "weekday": 4, "hour": 0, "minute": 0, "second": 0 }
2026-01-01T00:00:00
["year", "month", "day", "weekday", "hour", "minute", "second", "dst"]

Verified on Godot 4.7.2

Both scripts on this page were run headless on Godot 4.7.2 (4.7.2.stable.mono.official.ed1daf0bf) on 18 October 2026, and the output above is what Godot printed, unedited.

Where the check lives in Godot's source: [gdscript_analyzer.cpp line 3772, the message](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_analyzer.cpp#L3772), [Time in the class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/Time.xml).

Questions

How do I measure how long something took?
Read Time.get_ticks_usec() before and after. It is monotonic, unlike the system clock.
Is the system time local or UTC?
Local by default. Pass true to get_datetime_dict_from_system(true) for UTC.