Skip to reading
GDScript Programming & Godot

20. Dates and calendar values

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
Code example
func run() -> Dictionary:
    var date: Dictionary = Time.get_datetime_dict_from_unix_time(0)
    return {"year": date["year"], "month": date["month"], "day": date["day"]}

Time.get_datetime_dict_from_system returns the current calendar components; an optional UTC flag selects UTC rather than local system time. Time.get_datetime_string_from_system creates a display string. Unix timestamps represent seconds since the epoch.

PCA’s NowUnix, DateTimeNow, DateTimeString and UnixToDateTime are convenience wrappers. UnixToDateTime retains a compatibility UTC parameter, but the conversion itself uses Godot’s UTC timestamp dictionary. Do not use the system calendar clock as an unquestioned gameplay stopwatch.

Page 29 of 378Permalink
Go to page