You're not doing anything wrong. The code I posted was for GNU date
, and macOS uses BSD date
. Because of this, date
on a Mac works completely differently. For your use, you would use:
date -j -f "%d %B %Y %l:%M%p %Z" "24 January 2021 5:00PM PST" "+%s"
The command breaks down like this:
-
-j
– Do not try to change the system/computer date -
-f "%d %B %Y %l:%M%p %Z"
– This specifies the format of the date you are going to use -
"24 January 2021 5:00PM PST"
– This is the date itself to use as input -
"+%s"
– This is the format to use as the output
To get a full list of all of the format strings you can use for use with date -f
, check out the manpage for strftime(3)
, or see them here.