与 GMT 标准时间的偏移
Unix 内部是否存储机器与 GMT 的偏移量? 例如:印度标准时间是 GMT + 5:30。这个 5:30 存储在哪里吗?
我需要这个才能在如下脚本中使用它
if[[ off is "some value"]]
then
some statements
fi
Does Unix store the offset of the machine from GMT internally?
like for eg:india standard time is GMT + 5:30.is this 5:30 stored some where?
i need this to use it in a script like below
if[[ off is "some value"]]
then
some statements
fi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
传统上,在 UNIX 中,内核以与时区无关的形式保存当前时间,这是它向应用程序报告的内容。
应用程序参考环境变量和/或用户配置(对于不同的用户或一个用户的不同会话可能不同)来确定报告时间的时区。为此,磁盘上保存了一些表,其中保存了系统知道的所有时区(这些表需要不断更新,以适应夏令时算法的政治变化)。
Traditionally in UNIX, the kernel keeps the current time in a timezone-independent form, which is what it reports to applications.
Applications consult environment variables and/or user configuration (which can be different for different users or different sessions for the one user) to determine which timezone to report the time in. For this purpose, there are tables kept on disk which hold the offsets of all timezones that the system knows about (these tables need to be continuously updated for political changes to daylight saving algorithms).
以下程序在 EDT 中为我打印“-04:00”,并在我将 TZ 设置为“亚洲/加尔各答”时打印“04:30”:
随意使用/更改您想要的任何内容,然后从 shell 脚本中调用它。
The following program prints '-04:00' for me in EDT and prints '04:30' when I set TZ to 'Asia/Kolkata':
Feel free to use/change whatever you want and then call it from your shell script.
内核在内部保留 GMT 时间,当请求本地时间时,使用时区信息计算偏移量。这样,如果需要更改时区,则内部时钟不需要更改。
The kernel keeps GMT time internally, and when asked for the local time calculates the offset using the timezone information. This way, if a timezone change is required, internally, the clock doesn't need change.
在内核或驱动程序中,没有。
通常,它存储在名为 /etc/localtime 的文件中。该文件通常是指向其他地方的文件的链接,其中包含(以压缩形式)将 GMT 转换为本地时间的所有“规则”,包括夏令时开始和结束的时间、与 GMT 的偏移量等。
In the kernel or a driver, no.
Usually, it's stored in a file called /etc/localtime. That file is often a link to a file elsewhere that contains (in compressed form) all the "rules" for converting GMT to the local time, including when daylight saving time begins and ends, the offset from GMT, and so forth.