OSX
$ echo `date -d '1 day ago' +"%Y-%m-%d"`
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
$ echo `date -v-1d +"%Y-%m-%d"`
2014-10-23
$
Linux
$ echo `date -d '1 day ago' +"%Y-%m-%d"`
2014-10-23
$ echo `date -v-1d +"%Y-%m-%d"`
date: invalid option -- 'v'
Try 'date --help' for more information.
2つの環境揃えないとosxで書いたのがlinuxサーバーで動かない
$ brew install coreutils
All commands have been installed with the prefix 'g'.
If you really need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:
PATH="/opt/boxen/homebrew/opt/coreutils/libexec/gnubin:$PATH"
Additionally, you can access their man pages with normal names if you add
the "gnuman" directory to your MANPATH from your bashrc as well:
MANPATH="/opt/boxen/homebrew/opt/coreutils/libexec/gnuman:$MANPATH"
$ echo `gdate -d '1 day ago' +"%Y-%m-%d"`
2014-10-23
$ vim ~/.bashrc
alias date="gdate"
$ source ~/.bashrc
$ echo `date -d '1 day ago' +"%Y-%m-%d"`
2014-10-23
Top comments (0)