RTC相关

RTC唤醒 (Real Time Clock)

sudo rtcwake -m [mode] -s [seconds]

-m 选项指定进入的电源管理模式,可以是:
standby:进入待机模式
freeze:冻结模式
mem:挂起到内存
disk:挂起到磁盘
off:关机
no:不进入任何模式,只设置 RTC 唤醒
-s 选项指定多少秒后唤醒

手动设置RTC唤醒:

echo `date '+%s' -d '+5 minutes'` | sudo tee /sys/class/rtc/rtc0/wakealarm

清除唤醒时间:

sudo sh -c 'echo 0 > /sys/class/rtc/rtc0/wakealarm'

读取目前设定的RTC唤醒时间:

cat /sys/class/rtc/rtc0/wakealarm

这个读取的时间是一串数字,是以 Unix 时间戳(自 1970 年 1 月 1 日以来的秒数)表示的
转换成可读的时间:

date -d @1724815976

输出格式:
Wed Aug 28 11:32:56 CST 2024
可以直接:

#date -d @`cat /sys/class/rtc/rtc0/wakealarm`
Wed Aug 28 13:36:22 CST 2024

检查当前rtc时间(可以看看和系统时间是否对齐):

# cat /proc/driver/rtc 
rtc_time        : 03:40:38
rtc_date        : 2024-08-27
alrm_time       : 03:32:56
alrm_date       : 2024-08-28
alarm_IRQ       : yes
alrm_pending    : no
update IRQ enabled      : no
periodic IRQ enabled    : no
periodic IRQ frequency  : 1024
max user IRQ frequency  : 64
24hr            : yes
periodic_IRQ    : no
update_IRQ      : no
HPET_emulated   : yes
BCD             : yes
DST_enable      : no
periodic_freq   : 1024
batt_status     : okay

检查系统时间和RTC时间是否同步:

:~# hwclock --show && date
2024-08-27 13:45:53.419393+0800
Tue Aug 27 13:45:54 CST 2024

将系统时间写到RTC内:

sudo hwclock --systohc

将RTC时间同步到系统时间:

sudo hwclock --hctosys

单独设定RTC时间:

sudo hwclock --set --date="2024-08-27 12:34:56"

可以设定RTC时区(一般不用):
1.设定为UTC:

sudo timedatectl set-local-rtc 0

2.设定为本地时间,非UTC

sudo timedatectl set-local-rtc 1

查看信息:

:~# timedatectl status
                      Local time: Tue 2024-08-27 13:55:01 CST
                  Universal time: Tue 2024-08-27 05:55:01 UTC
                        RTC time: Tue 2024-08-27 05:55:01
                       Time zone: Asia/Shanghai (CST, +0800)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

详解:
本地时间(Local time):2024-08-27 13:55:01 CST
协调世界时(Universal time):2024-08-27 05:55:01 UTC
RTC 时间(RTC time):2024-08-27 05:55:01
时区(Time zone):Asia/Shanghai (CST, +0800)
系统时钟已同步(System clock synchronized):yes
systemd-timesyncd 服务活动(systemd-timesyncd.service active):yes
RTC 使用本地时区(RTC in local TZ):no
设定系统的时区为上海:

timedatectl set-timezone Asia/Shanghai

其他时区:

timedatectl list-timezones
  • 9
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值