Parsing dates in Mavericks

I'm sure this used to be valid:

$ date -d"2013-10-12T09:23:28+0100" +%h
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
        [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

But it seems not to be in Mavericks. Indeed, the example for parsing dates in man date also doesn't seem to work:

$ date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s"
Failed conversion of ``Thu 31 Oct 2013 21:05:29 GMT'' using format ``%a %b %d %T %Z %Y''
date: illegal time format
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
        [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

Any ideas on a workaround?


Here are two date commands that work on Mavericks to convert/extract time from date strings:

mac:~ me$ date -j -f "%Y-%m-%d %T" "2013-10-12 09:23:28" +%s
1381584208
mac:~ me$ date -j -f "%Y/%m/%d %T" "2013/10/22 10:45:00" +%h
Oct

It's not entirely clear what you seek, but hopefully these workable examples bridge the gap for your needs.


-d has set the kernel's value for daylight saving time in OS X's date at least since 10.6. The first command worked for me with GNU date (where -d specifies a date string):

$ gdate -d"2013-10-12T09:23:28+0100" +%h
Oct

The second command worked with the date that comes with 10.9 when I used the en_US locale but not when I used the en_GB locale:

$ date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s"
1383305706
$ date -j -f "%a %b %d %T %Z %Y" "`LC_TIME=en_GB date`" "+%s"
Failed conversion of ``Fri  1 Nov 2013 14:09:17 EET'' using format ``%a %b %d %T %Z %Y''
date: illegal time format
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

In OS X's date, -j disables attempting to set the date and -f specifies a format for parsing a date.