# 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".

Source: https://flockbay.com/godot/how-to-get-the-current-date-and-time-in-godot-4/ · Updated 2026-10-30

## 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"]
```

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

```
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](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.

Download Flockbay free: Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot. https://flockbay.com/download/

Related: [How to save and load a game in Godot 4: FileAccess](/godot/how-to-save-a-game-in-godot-4/), [How to parse JSON in Godot 4: JSON.parse_string()](/godot/how-to-parse-json-in-godot-4/), [How to get a random number in Godot 4: randi_range() and randf_range()](/godot/how-to-get-a-random-number-in-godot-4/), [How to set the window size in Godot 4: get_window().size](/godot/how-to-set-the-window-size-in-godot-4/), [Every verified Godot 4 answer](/godot/), [How do I connect Claude Code to Godot?](/docs/how-do-i-connect-claude-code-to-godot/)
