(1)date 显示或设置系统时间
date
2025年 09月 11日 星期四 23:32:18 CST
自显示自定义时间格式(常用格式化参数:%Y年、%m月、%d日、%H时(24 小时制)、%M分、%S秒):
date +"%Y-%m-%d %H:%M:%S"
2025-09-11 23:33:10
date +"%H:%M:%S %Y-%m-%d "
23:33:35 2025-09-11
显示当前时间的 Unix 时间戳(秒级,从 1970-01-01 00:00:00 UTC 开始)
date +%s
1757605375
显示 UTC 时间(协调世界时)
date -u
2025年 09月 11日 星期四 15:43:15 UTC
(2)设置时间:
date -s "2025-xx-xx 16:02:00"
(3)查看当前硬件时钟时间
hwclock
将系统时间同步到硬件时钟
hwclock -w
显示硬件时钟的时间标准(本地时间还是 UTC)
hwclock --debug | grep "RTC time"
(4) uptime - 查看系统运行时间
uptime
23:36:31 up 27 min, 1 user, load average: 0.07, 0.06, 0.06
(5) sleep 0.5 休眠0.5秒
sleep 0.5
(6)cal - 显示日历
sudo apt install ncal
cal 2025
(7)查看文件时间属性
stat hello.c
File: hello.c
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 917643 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ camera) Gid: ( 1000/ camera)
Access: 2025-09-11 23:45:06.616798321 +0800
Modify: 2025-09-11 23:45:06.616798321 +0800
Change: 2025-09-11 23:45:06.616798321 +0800
Birth: 2025-09-11 23:45:06.616798321 +0800
(8)时区相关的
显示当前时间 时区 NTP同步状态
imedatectl
Local time: 四 2025-09-11 23:50:10 CST
Universal time: 四 2025-09-11 15:50:10 UTC
RTC time: 四 2025-09-11 15:50:09
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
列出所有可用时区
timedatectl list-timezones
设置时区(如上海时区):
sudo timedatectl set-timezone Asia/Shanghai