23

linux嵌入式系统设置时间

 3 years ago
source link: http://mp.weixin.qq.com/s?__biz=MzUxMTk4MzY3MA%3D%3D&%3Bmid=2247484601&%3Bidx=1&%3Bsn=20da27daaad23fcafbaffd6689e24e3b
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

点击上方蓝字可直接关注!方便下次阅读。如果对你有帮助,麻烦点个在看或点个赞,感谢~

rIvERfJ.jpg!mobile

仰望星空的烟火

可以缓解颈椎疼痛

有时程序对系统时间有要求,这时需要设置系统的时区以及时间了。

1. 使用date指令查询当前系统时间:

未设置前:此时 时间为 Thu Sep 10 02:41:16 UTC 2020

UTC : 世界协调时间,又称世界标准时间。

2. 时区文件存储目录

/usr/share/zoneinfo/Asia/Shanghai ,该目录下存放着中国标准时间。新闻联播一般说北京时间,但是 linux 系统里面时区信息存储的是 Shanghai ,这里面没有北京地区。

3. 时间配置文件

/etc/localtime ,该文件表示系统当前使用的时间信息。

4. 修改系统时区时间

rm -f /etc/localtime  

ln -sf  /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime

注:我使用的嵌入式系统中没有/usr/share下没有 zoneinfo 文件夹,是从 ubuntu 桌面系统拷贝出来的。

③推测:可将 ubuntu 桌面系统中的 /usr/share/zoneinfo/Asia/Shanghai 文件重命名为 localtime 放置到嵌入式系统 /etc 目录下,未实际测试。 ln -sf 是文件的软连接,还可以再了解 linux 共享库的软连接。

注:嵌入式系统中不支持该指令tzselect

reboot 后生效

Rjuy2in.jpg!mobile

5. 修改后效果

多了8个小时。

VZzmQvQ.jpg!mobile

6. 断电重启后仍然生效

/etc/profile 添加 export TZ=CST-8 即可。

FBzMFfN.jpg!mobile

扩展:

Unix 时间戳

在计算机中看到的UTC时间都是从( 197001010:00:00) 开始计算秒数的。所看到的 UTC 时间那就是从 1970 年这个时间点起到具体时间共有多少秒。这个秒数就是 Unix 时间戳。

小结:

最近学习到了挺多新知识,需要赶快总结。

如何根据系统时间计算程序语句实际执行时间 ?

Linux C中如何屏蔽不同共享库中的同名函数 ?

都是一些小技巧。

如何设计方便复用的模块化程序 ?

欢迎关注公众号:

MZzeIjR.png!mobile


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK