Elixir doesn't include a timezone database by default, but it does support timezones if you add one. The easiest way is to use Tzdata.
- Add
{:tzdata, "~> 1.1"}
to mix.exs
- Add
config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase
to config/config.exs
- Use
DateTime.from_naive!/3
to convert to a timezone-aware DateTime
.
- Use
DateTime.compare/2
to compare the date to now.
~N[2000-01-01 10:10:10]
|> DateTime.from_naive!("US/Mountain")
|> DateTime.compare(DateTime.utc_now())
|> Kernel.==(:lt)
Output:
true
Config example:
# config/config.exs
import Config
config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…