一、date命令,会显示当前系统时间日期linux
[root@xuexi-001 ~]# date 2018年 09月 11日 星期二 21:10:08 CST
二、date命令,在shell中用处很是大;对文件后缀增长一个时间,以便后期管理nginx
三、date +%Y-%m-%d, date +%y-%m-%d 年月日shell
[root@xuexi-001 ~]# LANG=en 切换为英文显示 [root@xuexi-001 ~]# date Tue Sep 11 21:14:58 CST 2018 [root@xuexi-001 ~]# date +%Y 2018 四位的年 [root@xuexi-001 ~]# date +%y 18 两位的年 [root@xuexi-001 ~]# date +%m 09 月份 [root@xuexi-001 ~]# date +%M 16 分钟 [root@xuexi-001 ~]# date +%d 11 日期 [root@xuexi-001 ~]# date +%D 09/11/18 直接标记年月日,不过格式比较特殊 [root@xuexi-001 ~]# date +%Y%m%d 20180911 年月日 [root@xuexi-001 ~]# date +%F 2018-09-11 年月日,这种带横杠的
四、常见时间单位日志
[root@xuexi-001 ~]# date +%w 2 表示周二 [root@xuexi-001 ~]# date +%W 37 今年的第几周,今年的第二周 [root@xuexi-001 ~]# date +%h Sep 英文的月份 [root@xuexi-001 ~]# date +%H 21 小时 [root@xuexi-001 ~]# date +%S 00 秒 [root@xuexi-001 ~]# date +%s 1536672074 这是一个时间戳,距离1970总共过去多少秒
五、时间其余标记方法code
[root@xuexi-001 ~]# date +%H:%M:%S 21:22:47 [root@xuexi-001 ~]# date +%T 21:23:14
六、显示日历 cal命令,查看到日期date
[root@xuexi-001 ~]# cal September 2018 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
七、标记以前的日期方法
八、学会用date标记以前的日期时间戳
[root@xuexi-001 ~]# date -d "-1 day" Mon Sep 10 21:27:10 CST 2018 [root@xuexi-001 ~]# date -d "-1 day" +%F 2018-09-10 [root@xuexi-001 ~]# date -d "-1 month" +%F 2018-08-11 [root@xuexi-001 ~]# date -d "+1 year" +%F 2019-09-11 [root@xuexi-001 ~]# date -d "+1 hour" +%T 22:29:26 [root@xuexi-001 ~]# date -d "+1 min" +%T 21:30:55
九、时间戳ember
[root@xuexi-001 ~]# date +%s 1536672696 [root@xuexi-001 ~]# date -d @1536672696 Tue Sep 11 21:31:36 CST 2018
十、若想在linux系统中,把具体的日期换算成时间戳的时候,可使用date +%s -d "2018-09-11 21:22:11"英文
[root@xuexi-001 ~]# date +%s -d "2018-09-11 21:22:11" 1536672131 [root@xuexi-001 ~]# date -d @1536672131 Tue Sep 11 21:22:11 CST 2018