Why the discrepancy in date?

Dotan Cohen dotancohen at gmail.com
Sun Jan 8 14:50:47 UTC 2012


On Sun, Jan 8, 2012 at 14:06, Nils Kassube <kassube at gmx.net> wrote:
>> 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?
>

Because then I do not need the quotes. It is also ISO standard 8601:
http://en.wikipedia.org/wiki/ISO_8601

✈saturn:~$ date +%s -d "2006-12-31 22:00"
1167595200
✈saturn:~$ date +%s -d 2006-12-31t22:00
1167577200

That is interesting, I've never noticed that behaviour before.

>> ✈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'
>

Even specifying UTC (that is the Z timezone) doesn't help:
✈saturn:~$ date +%s -d "2006-12-31 22:00Z"
1167602400
✈saturn:~$ date -d @1167602400
Mon Jan  1 00:00:00 IST 2007
✈saturn:~$ date +%s -d "2006-12-31 22:00"
1167595200
✈saturn:~$ date -d @1167595200
Sun Dec 31 22:00:00 IST 2006
✈saturn:~$


I do not believe that there should be a difference when using the T separator.


-- 
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com




More information about the ubuntu-users mailing list