Emacs is two hours off from the system time. I tried to google for the problem, but no luck. What do I need to configure to correct this? I suspect this to be the difference from GMT to where I live (I'm in GMT+2 zone, that is, if I subtract from system time 2, I'll get the time in Emacs). So... maybe it's some locale settings?
I just messed up a git repository because of that: commits made through magit
used Emacs time, and placed them before the commits made by someone else :(
Here, I've added a screenshot showing the difference. The output from the date
is the correct time, but the time on the modeline fringe is wrong.
EDIT0:
It appears Stefan is right, and the time in Git is not connected to time in Emacs (the screenshot below is from Cygwin terminal).
This question is as relevant to Git as it is to Emacs - somehow they are using some system API that falls out of sync on my PC - and that is something I need to set up to align them on it. The question is what is that setting they both use?
EDIT1:
Here's the code that Emacs uses to retrieve the time, 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;
}
And it looks like it gets tz
wrong. I don't know what _ftime
is - but it doesn't seem to be defined in Emacs' sources, this must come from elsewhere...
Some more research:
SBCL installed from MSI gives this:
(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: (actual time is 12:56)
It is now 10:56:55 of Tuesday, 6/04/2013 (GMT+0)
Perl from ActivePerl (installed from Cygwin):
$now = localtime;
print $now;
Output: (actual time is 12:52)
Tue Jun 4 12:52:17 2013
CPython, installed from MSI.
import datetime
str(datetime.datetime.now())
Output: (actual time is 13:03)
2013-06-04 11:03:49.248000
JavaScript, Node.js, installed from MSI:
Date();
Output: (actual time is 12:09)
Tue Jun 04 2013 10:09:05 GMT+0000 (IST)
Bash (Cygwin):
$ date
Output: (actual time is 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: (actual time is 13:13)
Today: 04-Jun-13 13:13:37
EDIT2:
Today our sysadmin gave me a VM to move my stuff to. Interestingly, what happened there is that this time I got Git through Cygwin, and now Git shows correct times. Emacs, however, still shows wrong time. Python, (not the one bundled with Cygwin) shows correct time if launched from Cygwin and wrong time if launched from Emacs! SBCL shows wrong time no matter how it is launched.
Is it possible this is some network setting? Perhaps something to do with how Windows synchronizes system time?