I tried the following on mac terminal, and found it has some problem:
date –j –f '%d-%b-%Y' "22-Aug-2013" "+%s"
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]
Could anybody help me to parse this string 22-Aug-2013
and get the epoch seconds?
You're using the wrong character before your option characters j
and f
— you’re using an en dash (–, U+2013) rather than a hyphen (-, U+002D). Unix tools don't tend to be terribly Unicode savvy when parsing command-line arguments :-)
You may find TextWrangler/BBEdit’s Character Inspector palette useful, or if you're more of an Emacs person, M-x describe-char
.
I had no issue in OS X 10.8.4:
$ date -j -f '%d-%b-%Y' "22-Aug-2013" "+%s"
1377223888
$ date -j -f '%s' 1377223888
Thu Aug 22 21:11:28 CDT 2013
Note that it is taking the current time and including it with the specified date. It would be more accurate to explicitly set the time:
$ date -j -f '%d-%b-%Y %T' "22-Aug-2013 00:00:00" "+%s"
1377147600
$ date -j -f '%s' 1377147600
Thu Aug 22 00:00:00 CDT 2013
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With