Emacs 比系统时间差两个小时。我试图用谷歌搜索这个问题,但没有运气。我需要配置什么来纠正这个问题?我怀疑这是从 GMT 到我住的地方的差异(我在 GMT+2 区域,也就是说,如果我从系统时间 2 中减去,我会在 Emacs 中得到时间)。所以......也许是一些语言环境设置?
我只是因为这个搞砸了一个 git 存储库:通过magit
使用 Emacs 时间进行的提交,并将它们放在其他人的提交之前:(
在这里,我添加了一个显示差异的屏幕截图。的输出date
是正确的时间,但模式线边缘的时间是错误的。
编辑0:
看来 Stefan 是对的,Git 中的时间与 Emacs 中的时间没有关联(下面的屏幕截图来自 Cygwin 终端)。
这个问题与 Git 和 Emacs 一样重要——不知何故,他们正在使用一些在我的 PC 上不同步的系统 API——这是我需要设置的东西以使它们对齐。问题是他们都使用的设置是什么?
编辑1:
这是 Emacs 用来检索时间的代码,afaik:
/* Emulate gettimeofday (Ulrich Leodolter, 1/11/95). */
int
gettimeofday (struct timeval *__restrict tv, struct timezone *__restrict tz)
{
struct _timeb tb;
_ftime (&tb);
tv->tv_sec = tb.time;
tv->tv_usec = tb.millitm * 1000L;
/* Implementation note: _ftime sometimes doesn't update the dstflag
according to the new timezone when the system timezone is
changed. We could fix that by using GetSystemTime and
GetTimeZoneInformation, but that doesn't seem necessary, since
Emacs always calls gettimeofday with the 2nd argument NULL (see
current_emacs_time). */
if (tz)
{
tz->tz_minuteswest = tb.timezone; /* minutes west of Greenwich */
tz->tz_dsttime = tb.dstflag; /* type of dst correction */
}
return 0;
}
看起来它tz
出错了。我不知道是什么_ftime
- 但它似乎没有在 Emacs 的来源中定义,这一定来自其他地方......
更多研究:
从 MSI 安装的 SBCL 给出了这个:
(defconstant *day-names*
'("Monday" "Tuesday" "Wednesday"
"Thursday" "Friday" "Saturday" "Sunday"))
(multiple-value-bind
(second minute hour date month year day-of-week dst-p tz)
(get-decoded-time)
(format t "It is now ~2,'0d:~2,'0d:~2,'0d of ~a, ~d/~2,'0d/~d (GMT~@d)"
hour minute second (nth day-of-week *day-names*)
month date year (- tz)))
输出:(实际时间是12:56)
It is now 10:56:55 of Tuesday, 6/04/2013 (GMT+0)
来自 ActivePerl 的 Perl(从 Cygwin 安装):
$now = localtime;
print $now;
输出:(实际时间是12:52)
Tue Jun 4 12:52:17 2013
CPython,从 MSI 安装。
import datetime
str(datetime.datetime.now())
输出:(实际时间是13:03)
2013-06-04 11:03:49.248000
从 MSI 安装的 JavaScript、Node.js:
Date();
输出:(实际时间是12:09)
Tue Jun 04 2013 10:09:05 GMT+0000 (IST)
重击(Cygwin):
$ date
输出:(实际时间是13:10)
04 Jun, 2013 13:10:37
C#:
using System;
namespace TestTime
{
class Program
{
static void Main(string[] args)
{
DateTime d = DateTime.Now;
Console.WriteLine("Today: {0}", d);
Console.ReadLine();
}
}
}
输出:(实际时间是13:13)
Today: 04-Jun-13 13:13:37
编辑2:
今天我们的系统管理员给了我一个虚拟机来移动我的东西。有趣的是,这次我通过 Cygwin 获取了 Git,现在 Git 显示了正确的时间。然而,Emacs 仍然显示错误的时间。Python,(不是与 Cygwin 捆绑的)如果从 Cygwin 启动则显示正确的时间,如果从 Emacs 启动则显示错误的时间!SBCL 无论如何启动都会显示错误的时间。
这可能是一些网络设置吗?也许与 Windows 如何同步系统时间有关?