Mac using date to display seconds has “wrong time” error

I tried the following on a mac terminal and found that it has some problems:

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] 

Can someone help me parse this line 22-Aug-2013 and get the era of seconds?

+4
source share
2 answers

You are using the wrong character in front of your j and f option characters - you are using en dash (-, U + 2013), not a hyphen (-, U + 002D). Unix tools do not tend to be terribly Unicode savvy when parsing command line arguments :-)

You may find the CharacterWrangler / BBEdits Character Inspector palette useful, or if you're more like Emacs, Mx describe-char .

+8
source

I had no problems 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 

Please note that it takes the current time and includes it with the specified date. It would be more accurate to indicate 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 
+2
source

Source: https://habr.com/ru/post/1498785/


All Articles