DateTime():tz()
Sets the DateTime object's timezone to a specified timezone ID.
Signature
tz(timeZoneId: string): DateTime
Parameters
Parameter | Type | Description |
---|---|---|
timeZoneId | string | The ID of the timezone to set (e.g., "America/New_York", "Europe/London"). A list of available timezone IDs can be foundhere. |
Returns
- Type:
DateTime
- The current
DateTime
instance, with its timezone set to the specified ID, allowing for method chaining.
Examples
local now = DateTime()
toast("Local time: " .. now:format("yyyy-MM-dd HH:mm:ss Z"))
now:tz("America/New_York")
toast("New York time: " .. now:format("yyyy-MM-dd HH:mm:ss Z"))
now:tz("Europe/London")
toast("London time: " .. now:format("yyyy-MM-dd HH:mm:ss Z"))