在嵌入式 Linux 系统上设置时区

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9862953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:23:22  来源:igfitidea点击:

Set timezone on embedded Linux system

linuxtimezone

提问by fred basset

I have a small uCLinux system, how do I set the timezone on uCLinux?

我有一个小型 uCLinux 系统,如何在 uCLinux 上设置时区?

Thanks, Fred

谢谢,弗雷德

回答by wallyk

If the system uses BusyBox, add this command to /etc/inittab:

如果系统使用 BusyBox,则将此命令添加到/etc/inittab

setenv TZ PDT

If not using busybox, just set an environment variable in your application's initialization code:

如果不使用busybox,只需在应用程序的初始化代码中设置一个环境变量:

putenv ("TZ=PDT");

I have chosen US Pacific Daylight Time for these examples, but maybe that does not apply to you.

我为这些示例选择了美国太平洋夏令时,但这可能不适用于您。

回答by sshambaugh

I export TZ=PDT (my system doesn't have setenv), and TZ is definitely being set and is available to the subsequent script that runs the ntpclient. The log entries in /var/log/messagesare all in UTC, as is the output of the date command.

我导出 TZ=PDT(我的系统没有setenv),并且 TZ 肯定已设置并且可用于运行ntpclient. 中的日志条目/var/log/messages都采用 UTC,日期命令的输出也是如此。

export TZ=PST8PDT

回答by user2746729

Edit $HOME/.profileor $HOME/.bash_profileappending the following line:

编辑$HOME/.profile$HOME/.bash_profile附加以下行:

TZ='Asia/Kolkata'; export TZ

Then log out and log in again.

然后注销并重新登录。