Why the discrepancy in date?
Nils Kassube
kassube at gmx.net
Sun Jan 8 12:06:26 UTC 2012
Dotan Cohen wrote:
> For determining the current date, my date functions roundtrip just
> fine: ✈saturn:~$ date
> Sun Jan 8 12:32:24 IST 2012
> ✈saturn:~$ date +%s
> 1326018753
> ✈saturn:~$ date -d @1326018753
> Sun Jan 8 12:32:33 IST 2012
>
>
> However, for dates in the past they do not:
> ✈saturn:~$ date +%s -d 2006-12-31t22:00
> 1167577200
Interesting - why do you use "t" instead of " " as a separator between
date and time?
> ✈saturn:~$ date -d @1167577200
> Sun Dec 31 17:00:00 IST 2006
> ✈saturn:~$
>
> Notice that 22:00 became 17:00 - that is a five hour difference!
>
> As can be seen, I am on IST, which is UTC+2, so it does not account
> for the discrepancy:
Well, IST probably isn't the reason because here the same happens with
my time zone being CET (UTC+1):
~/ > date +%s -d 2006-12-31t22:00
1167577200
~/ > LC_ALL=C date -d @1167577200
Sun Dec 31 16:00:00 CET 2006
(I used the "LC_ALL=C" to get an English output string.)
However if I use " " instead of "t" as separator between date and time,
I get what I would expect:
~/ > date +%s -d "2006-12-31 22:00"
1167598800
~/ > LC_ALL=C date -d @1167598800
Sun Dec 31 22:00:00 CET 2006
So to me it looks like your "t" separator makes the date command use the
time zone UTC+7 intead of your local time zone. Furthermore, if I
specify a time zone together with your "t" separator, date complains
about an invalid date:
~/ > LC_ALL=C date +%s -d "2006-12-31t22:00 UTC"
date: invalid date `2006-12-31t22:00 UTC'
Nils
More information about the ubuntu-users
mailing list