Elixir-Timex检测英国夏令时的开始和结束时间

时间:2019-04-23 14:04:17

标签: timezone elixir timex

我发现Timex.Timezone.convert(t, "Europe/London")返回了一个DateTime格式的#<DateTime(2019-04-24T17:00:00 Europe/London (+01:00:00))>对象。我的问题是BST在10月结束,Timex.Timezone.convert(t, "Europe/London")会自动调整并返回UTC时间吗?

1 个答案:

答案 0 :(得分:1)

是的,它将返回+00:00 GMT Europe/London而不是+01:00 BST Europe/London

正如注释中所建议的那样,很容易进行检查:假设将{:timex, "~> 3.0"}添加为依赖项,请运行

$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>