utc_offset in elixir return 时区偏移不正确
utc_offset in elixir return incorrect offset for time zones
我可能不理解这里的某些东西 - 但这看起来更直接。
iex> {:ok, datetime_with_tz} = DateTime.now("Europe/London", Tzdata.TimeZoneDatabase)
{:ok, #DateTime<2020-05-02 21:57:11.136512+01:00 BST Europe/London>}
iex> DateTime.utc_now
~U[2020-05-02 20:57:21.869835Z]
//correct as it's already in utc
iex> DateTime.utc_now.utc_offset
0
// incorrect this should be 3600 i.e +01:00 hours of offset and not 0 .. ?
iex> datetime_with_tz.utc_offset
0
那是因为伦敦通常是 UTC+00:00,由于夏令时(BST 代表英国夏令时),目前是 +01:00。
DateTime std_offset 可以处理这个问题。
iex(1)> {:ok, datetime_with_tz} = DateTime.now("Europe/London", Tzdata.TimeZoneDatabase)
iex(2)> datetime_with_tz.std_offset
3600
我可能不理解这里的某些东西 - 但这看起来更直接。
iex> {:ok, datetime_with_tz} = DateTime.now("Europe/London", Tzdata.TimeZoneDatabase)
{:ok, #DateTime<2020-05-02 21:57:11.136512+01:00 BST Europe/London>}
iex> DateTime.utc_now
~U[2020-05-02 20:57:21.869835Z]
//correct as it's already in utc
iex> DateTime.utc_now.utc_offset
0
// incorrect this should be 3600 i.e +01:00 hours of offset and not 0 .. ?
iex> datetime_with_tz.utc_offset
0
那是因为伦敦通常是 UTC+00:00,由于夏令时(BST 代表英国夏令时),目前是 +01:00。
DateTime std_offset 可以处理这个问题。
iex(1)> {:ok, datetime_with_tz} = DateTime.now("Europe/London", Tzdata.TimeZoneDatabase)
iex(2)> datetime_with_tz.std_offset
3600