DST指的是什么时区?

What timezone does DST refer to?

我在 ubuntu 16.04 中使用 WSL,今天遇到网络问题。这是日期输出

$ date
Thu Sep 21 13:37:00 DST 2017

夏令时指的是什么?我知道它代表 "Daylight savings time",但那是 not a timezone name。我怀疑这是一个人为的时区,会在春分时改变,这可以解释我今天的问题。

我能够通过将时区设置为 US/Pacific 来解决我的问题,这将输出更改为 PDT:

$ date
Thu Sep 21 13:37:00 PDT 2017

但是,我有第二台机器也有同样的问题,我很好奇它认为它在哪个时区。

有没有办法从系统中获取对应于DSTX/Y字符串(Olson数据库名称)?

据我所知,本例中的 DST 实际上是指夏令时。

Ubuntu 因有关 DST 调整的错误而臭名昭著:https://askubuntu.com/questions/595569/update-time-for-daylight-savings-time-set-system-clock-to-utc-time-and-stay-in

更新:这个答案可能是错误的; OP报告的输出与我的假设不一致。

我认为这是一个无法识别的时区,被 date 命令解释为 UTC。

在我的 Ubuntu 14.04 系统上:

$ date -u ; TZ=DST date ; TZ=NOSUCHTIMEZONE date
Thu Sep 21 21:04:44 UTC 2017
Thu Sep 21 21:04:44 DST 2017
Thu Sep 21 21:04:44 NOSUCHTIMEZONE 2017
$ 

可能是某些东西将您的 $TZ 环境变量设置为 DST

检查您的环境 (echo $TZ)。如果它不打印 DST,我错了。 (编辑:OP 说 $TZ 是空的。)

(/usr/share/zoneinfo下面没有叫DST的东西。)

TL;DR WSL 在 /usr/share/zoneinfo/Msft/localtime 动态生成一个假的时区信息文件,硬链接到 /etc/localtime。 Msft 文件使用虚构名称 DSTSTD,它们不代表特定时区。


实际发生的事情是 WSL 试图在 Linux 中匹配您的 Windows 时区。这是一个非常重要的映射,如 here (discussion). So rather than trying to hit a constantly moving target, what I believe WSL does is use the Windows API to get the Windows Timezone info, and based off of that information, it dynamically generates a timezone info file.

所示

我相信 wslhost(特别是 C:\Windows\System32\lxss\LxssManager.dll 中的代码)在 Windows 中对您当前的时区进行此检查,并写入 /usr/share/zoneinfo/Msft/localtime 文件。这就是为什么当 Windows 中的时区发生变化时,您会立即在已经 运行 的 WSL 中看到影响。但是由于没有从 Windows 时区到 Linux 或 POSIX 时区的完美映射,wslhost 可能只是 wings 名称,并且这就是 DST 发挥作用的地方。

更新: 实际上,我认为它只是说 "DST" 如果你在夏令时时区, "STD" 对于非 DST 时区(标准我假设)。

所以 "What timezone does DST stand for" 的答案是 none,任何 Linux 程序都会尝试将 /etc/localtime 匹配到 /usr/share/zoneinfo 中的时区文件(通过阅读链接或只是搜索),只有每个人都会得到 "Msft/localtime" 作为答案。 "Technically accurate, but totally useless" 个答案。