Emacs and Git show wrong time on Windows

最后都变了- 提交于 2019-12-01 18:04:40
Palec

Windows programs get timezone info from the system where you set it via control panel. Time itself can be set manually too, but it is more usual to let Windows synchronize with time servers via Windows Time Service (NTP-based; for usage see WinXP support article). AFAIK Windows Time Service has nothing to do with timezone and is the only network-related thing involved in the problem.

Cygwin programs should in theory behave the same way as on any other *NIX. They get the timezone information from /etc/localtime file or TZ environment variable. In my case (Debian), /etc/localtime is a copy of /usr/share/zoneinfo/Europe/Prague, but it could be a symlink pointing to that location as well. TZ can contain path relative to /usr/share/zoneinfo and takes precedence over /etc/localtime.

Practice is a different story. According to a thread on Cygwin mailing list, Microsoft C runtime (mscrt*.dll) has extremely outdated timezone handling and it is used for non-Cygwin programs. This is consistent with the results you are getting. Related technical info is in a thread from August 2005 and a related one from May 2010.

There is a work-around for Python already posted on SO and exactly the same for C++, which has a more brief explanation of the MSCRT problem than the previously linked threads.

Maybe Emacs has something special to do with the issue. A February 2009 message on GNU Emacs developers mailing list reports Emacs 22.3 displays correct time while Emacs 23 not. Following advice from a reply, the author posts the report to Cygwin mailing list – but gets no reply. December 2012 the issue is solved by docummenting it and its workaround (see /usr/share/doc/Cygwin/emacs.README). I don't have Cygwin and cannot find this file in its CVS, so please edit my answer with the info from there.

Personally I think that setting (and exporting) TZ environment variable in your ~/.profile would be a good idea. Cygwin obviously has broken timezone handling, so overriding everything related should be the safest thing to do as it leaves just a little room for black magic. Maybe tzset will work, maybe it won't and you'll have to set your timezone to a constant value.

Try googling for „timezone“ at Cygwin.com for more resources.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!