Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Time zone using tzdata

notebooks/tzdata.livemd

Time zone using tzdata

Mix.install([
  {:tzdata, "~> 1.1"}
])

# By default TZ database is Calendar.UTCOnlyTimeZoneDatabase
Calendar.UTCOnlyTimeZoneDatabase = Application.get_env(:elixir, :time_zone_database)

# Replace it with Tzdata.TimeZoneDatabase
Application.put_env(:elixir, :time_zone_database, Tzdata.TimeZoneDatabase)

Resources

Time now in different time zones

DateTime.utc_now()
DateTime.now!("Asia/Tokyo")
DateTime.now!("America/New_York")
# explicitly with TZ database
DateTime.now("Europe/Copenhagen", Tzdata.TimeZoneDatabase)
now = DateTime.now!("Asia/Tokyo")
oshogatsu = DateTime.new!(~D[2023-01-01], ~T[01:01:00], "Asia/Tokyo")
awesome = oshogatsu

DateTime.diff(awesome, now, :hour)