How do I convert a Unix timestamp to a local DateTime in Godot for a specific IANA time zone while respecting DST?
0 reputation · 13 Jun 2020, 13:26 UTC
0 reputation · 13 Jun 2020, 13:26 UTC
When working with dates in Godot 4.x, I receive a Unix timestamp (seconds since the epoch) and need to represent it as a local date/time for a specific IANA time zone, such as “Europe/Paris”. The engine provides OS.get_unix_time() and the Date class, but it is unclear whether these functions automatically apply the zone’s offset or if I must calculate it manually, especially considering daylight‑saving transitions.
I would like to know the recommended, built‑in way to perform this conversion while preserving historic offset changes and DST rules, without relying on external plugins or manual offset tables. Specifically: Does the Date constructor accept a time‑zone identifier to interpret a timestamp directly? If not, what is the correct procedure to convert a Unix timestamp to a Date, then apply the appropriate offset and DST adjustment for a given zone? Are there any built‑in utilities, such as TimeZone or similar, that can handle historic offset changes for IANA zones?
35775 reputation · 13 Jun 2020, 19:05 UTC
Based on the information currently available, Godot 4.x does not expose a built‑in API that directly interprets a Unix timestamp using an arbitrary IANA time zone identifier while applying historic offset changes and DST rules. The Date class can be constructed from a Unix timestamp, but it treats the value as UTC and then converts it to the system local time zone of the host machine. To obtain a date/time for a specific IANA zone (e.g., "Europe/Paris") you would need to either:
Date accordingly.Because the supplied sources do not contain any Godot‑specific documentation on time‑zone handling, the exact steps cannot be confirmed here. For a definitive solution, consult the official Godot 4.x documentation, the OS class reference, or community‑maintained plugins that add IANA zone support.
Use comments to ask for clarification. Post a solution as an answer.
5,910 reputation · 13 Jun 2020, 14:21 UTC
The Godot 4.3+ Time singleton can convert a Unix timestamp to UTC or the host’s system local time, but it does not accept an IANA zone identifier such as Europe/Paris. The only zone‑aware helper available is Time.get_time_zone_from_system(), which reports the machine’s current zone and can be used only to adjust for the local offset.
tzdata database.In a 4.3 project you can still use Time.get_datetime_dict_from_unix_time(t, true) to get a UTC dict, then apply the offset you obtain from an external lookup before converting back to a Date if you need a full Date instance.