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?
26525 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.
No question comments on this page.