不同Unix环境下date计算日期的用法
生活随笔
收集整理的這篇文章主要介紹了
不同Unix环境下date计算日期的用法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
轉自:http://blog.rootshell.be/2006/05/04/solaris-yesterday-date/
Solaris & yesterday date?
The GNU version of date(1) has a nice flag –date. It’s very easy to format dates in the past or future:
$ date +%d-%m-%Y 04-05-2006 $ date --date yesterday +%d-%m-%Y 03-05-2006 $ date --date "-6 months" +%d-%m-%Y 04-11-2005The Solaris version of date(1) has no such nice flags. So, how to print another date?
Direct in a shell:
$ YESTERDAY=`TZ=GMT+24 date +%d-%m-%Y`; echo $YESTERDAY 03-05-2006 $ YESTERDAY=`TZ=GMT-48 date +%d-%m-%Y`; echo $YESTERDAY 06-05-2006But, in this case, we are limited to a few days in the past or future. Another solution is Perl:
$ perl -e 'use POSIX qw(strftime); print strftime "%a %b %e %H:%M:%S %Y",/ localtime(time()- 3600*24*2);' Tue May 2 14:59:41 2006總結
以上是生活随笔為你收集整理的不同Unix环境下date计算日期的用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 股票商誉在哪里看
- 下一篇: ORACLE网络连接配置与文件:list