您现在的位置是:网站首页> 编程资料编程资料
Shell中取今天、昨天、前天的时间操作代码_linux shell_
2023-05-26
315人已围观
简介 Shell中取今天、昨天、前天的时间操作代码_linux shell_
1. 取今天时间
复制代码 代码如下:
$date -d "now" +%Y-%m-%d
2. 取昨天时间
复制代码 代码如下:
$date -d "yesterday" +%Y-%m-%d
$date -d "1 days ago" +%Y-%m-%d
## -d, --date=STRING display time described by STRING, not `now'
STRING可以为‘now' 、 ‘yesterday'、 ‘n days ago'
‘n days ago' 表示n天前的那一天
3. 取前天时间
复制代码 代码如下:
$date -d "2 days ago" +%Y-%m-%d
效果展示:
复制代码 代码如下:
$ date
2014年 07月 31日 星期四 20:48:32 CST
$ date -d "now" +%Y-%m-%d
2014-07-31
$ date -d "yesterday" +%Y-%m-%d
2014-07-30
$ date -d "2 days ago" +%Y-%m-%d
2014-07-29
您可能感兴趣的文章:
相关内容
- Shell脚本判断Apache进程是否存在_linux shell_
- Shell脚本监控网站页面正常打开情况_linux shell_
- shell中使用echo打印彩色字体和彩色背景的方法_linux shell_
- Shell脚本实现温和方式重启Centos系统_linux shell_
- Shell脚本判断Linux系统是32位还是64位的几种方法分享_linux shell_
- Shell脚本中调用、引用、包含另外一个脚本文件的两种方法_linux shell_
- shell脚本实现批量测试局域网主机是否在线_linux shell_
- shell脚本实现文件锁功能_linux shell_
- shell中的数组操作小结和冒泡排序实现脚本分享_linux shell_
- Bash Shell 注释多行的几种方法_linux shell_
