linux命令之date
linux命令date用来设置和显示系统日期和时间
date [参数]
| 参数 | 说明 |
| -s | 修改并设置时间 |
| -d | 可以显示以前和未来的时间 |
| %H | 小时 |
| %M | 分钟 |
| %S | 秒 |
| %X | 等价于%H %M %S |
| %F | 显示当前所有时间属性 |
| %Y | 完整年份 |
| %m | 月 |
| %d | 日 |
| %A | 星期的全称 |
命令:
date -s "2023-10-31 12:00:00"
- [root@rhel77 ~]# date
- Thu Oct 19 15:24:24 CST 2023
- [root@rhel77 ~]# date -s "2023-10-31 12:00:00"
- Tue Oct 31 12:00:00 CST 2023
- [root@rhel77 ~]# date
- Tue Oct 31 12:00:01 CST 2023
- [root@rhel77 ~]#
命令:
date +%F -d "-2day"
- [root@rhel77 ~]# date
- Thu Oct 19 15:25:55 CST 2023
- [root@rhel77 ~]# date +%F -d "-2day"
- 2023-10-17
- [root@rhel77 ~]#
命令:
date +%F -d "+2day"
- [root@rhel77 ~]# date
- Thu Oct 19 15:26:36 CST 2023
- [root@rhel77 ~]# date +%F -d "+2day"
- 2023-10-21
- [root@rhel77 ~]#
命令:
date +%H
- [root@rhel77 ~]# date +%H
- 15
- [root@rhel77 ~]#
命令:
date +%M
- [root@rhel77 ~]# date +%M
- 29
- [root@rhel77 ~]#
命令:
date +%S
- [root@rhel77 ~]# date +%S
- 22
- [root@rhel77 ~]#
命令:
date +%X
- [root@rhel77 ~]# date +%X
- 03:30:16 PM
- [root@rhel77 ~]#
命令:
date +%F
- [root@rhel77 ~]# date +%F
- 2023-10-19
- [root@rhel77 ~]#
命令:
date +%Y
- [root@rhel77 ~]# date +%Y
- 2023
命令:
date +%m
- [root@rhel77 ~]# date +%m
- 10
命令:
date +%d
- [root@rhel77 ~]# date +%d
- 19
命令:
date +%A
- [root@rhel77 ~]# date +%A
- Thursday
- [root@rhel77 ~]#