Emacs 与系统时间相差两个小时。我尝试用谷歌搜索这个问题,但没有成功。我需要配置什么来纠正这个问题?我怀疑这是从 GMT 到我住的地方的差异(我在 GMT+2 时区,也就是说,如果我从系统时间 2 中减去,我将得到 Emacs 中的时间)。那么...也许是一些区域设置?
我只是搞乱了 git 存储库,因为:通过提交magit
使用 Emacs 时间,并将它们放在其他人所做的提交之前:(
在这里,我添加了一个屏幕截图来显示差异。的输出date
是正确的时间,但模型线边缘的时间是错误的。
EDIT0:
看来 Stefan 是对的,Git 中的时间与 Emacs 中的时间没有关联(下面的屏幕截图来自 Cygwin 终端)。
这个问题与 Git 和 Emacs 一样相关 - 不知何故,他们使用了一些在我的 PC 上不同步的系统 API - 这是我需要设置的东西,以使它们在它上保持一致。问题是他们都使用什么设置?
EDIT1:
这是 Emacs 用于检索时间的代码,据我所知:
/* 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)))
Output: (实际时间为12点56分)
It is now 10:56:55 of Tuesday, 6/04/2013 (GMT+0)
ActivePerl 中的 Perl(从 Cygwin 安装):
$now = localtime;
print $now;
Output: (实际时间为12点52分)
Tue Jun 4 12:52:17 2013
Python,从 MSI 安装。
import datetime
str(datetime.datetime.now())
Output: (实际时间为13:03)
2013-06-04 11:03:49.248000
JavaScript、Node.js,从 MSI 安装:
Date();
Output: (实际时间为12点09分)
Tue Jun 04 2013 10:09:05 GMT+0000 (IST)
重击(Cygwin):
$ date
Output: (实际时间为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();
}
}
}
Output: (实际时间为13点13分)
Today: 04-Jun-13 13:13:37
EDIT2:
今天,我们的系统管理员给了我一个虚拟机来将我的东西移动到其中。有趣的是,这次我通过 Cygwin 获取了 Git,现在 Git 显示了正确的时间。然而,Emacs 仍然显示错误的时间。 Python(不是与 Cygwin 捆绑在一起的)如果从 Cygwin 启动则显示正确的时间,如果从 Emacs 启动则显示错误的时间! SBCL无论如何启动都显示错误的时间。
这有可能是某种网络设置吗?也许与 Windows 如何同步系统时间有关?