简体   繁体   中英

Elixir - Timex detecting when British Summer Time starts and ends

I found out that Timex.Timezone.convert(t, "Europe/London") returns a DateTime object of this format: #<DateTime(2019-04-24T17:00:00 Europe/London (+01:00:00))> . My question is when BST ends in October, will Timex.Timezone.convert(t, "Europe/London") automatically adjust and return the UTC time?

Yes, it will return +00:00 GMT Europe/London instead of +01:00 BST Europe/London .

As suggested in the comments, it's easy to check this: assuming that {:timex, "~> 3.0"} is added as a dependency, run

$iex -S mix
iex(1)> t = DateTime.from_naive!(~N[2019-11-01 13:26:08.003], "Etc/UTC")
#DateTime<2019-11-01 13:26:08.003Z>
iex(2)> Timex.Timezone.convert(t, "Europe/London")                      
#DateTime<2019-11-01 13:26:08.003+00:00 GMT Europe/London>
iex(3)> t = DateTime.from_naive!(~N[2019-10-01 13:26:08.003], "Etc/UTC")
#DateTime<2019-10-01 13:26:08.003Z>
iex(4)> Timex.Timezone.convert(t, "Europe/London")                      
#DateTime<2019-10-01 14:26:08.003+01:00 BST Europe/London>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM