メインコンテンツまでスキップ

DateTime():tz()

DateTime オブジェクトのタイムゾーンを指定したタイムゾーン ID に設定します。

シグネチャ

tz(timeZoneId: string): DateTime

パラメータ

パラメータ説明
timeZoneIdstring設定するタイムゾーンの ID(例: "America/New_York", "Europe/London")。利用可能なタイムゾーン ID の一覧はこちらで確認できます。

戻り値

  • 型: DateTime
  • 現在の DateTime インスタンス。タイムゾーンが指定した ID に設定され、メソッドチェーンが可能です。

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"))