Linux时间日期类指令


date:

显示当前日期:
date

显示当前年份
date +%Y
date +%y

显示当前月份:
date +%m

显示当前天:
date +%d

同理,时分秒为%H,%M,%S.


自定义显示格式的一个例子:
date "+%Y--+%m--%d"
例如会显示2021--02--26

执行效果:
在这里插入图片描述

设置日期:

设置时间
date -s 字符串表示的时间

例如:
date -s "2020-10-10 10:10:10"

执行该指令需要root权限.

cal:

查看日历
cal [选项]

查看当前日历:
cal

查看2021年的日历:
cal 2021

猜你喜欢

转载自blog.csdn.net/weixin_44178736/article/details/114087759