Skip to content

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 WindowsDownload for Linux

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.

More on this: How to make a game like Wordle

Reproduce it

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

GDScript
extends Node

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

What Godot 4.7.2 prints

Output
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.

GDScript
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

Output
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"]

Run this fix with your agent

Flockbay is the Godot editor with an AI agent built in. Paste this into Flockbay's chat, or into Claude Code or Codex connected to Flockbay over MCP: the agent finds the cause in your project, applies the fix, runs the game headless and reads Godot's output to check it.

Prompt
How to get the current date and time in Godot 4: the Time singleton 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". Where this calls for a change in my Godot 4 project, make it, then run the game headless and check Godot's output for errors.

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, Time in the class reference.

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.

Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.

Download Flockbay free