Getting the current date for a timezone with Elixir

Issue: Getting the (current or otherwise) date for a specific timezone can be involve some trickiness.

Example: I want to show the current date in New York, even though I reside in Austin, TX. If it is 12/11/2020 11:39 PM CT:

  • The display for NY data should show 12/12/2020
  • A display for Austin, TX would show 12/11/20202

One solution:

NOTE: When dealing with DateTimes to save to a database, leaving the microseconds on can cause issues. I’m surprised the DateTime result doesn’t default to the more compatible format (TBD on whether from Elixir or Timex). See https://github.com/riverrun/phauxth-example/issues/10

Leave a Reply

Your email address will not be published. Required fields are marked *