大网数据广告活动
服务器运维问答

Linux get UTC offset from current (or other) timezones on given date and time

· 52CE 我爱测

In Chile the case is very particular as the days of daylight saving changes are different a year from another... Is there a function to get for given day at given UTC time the UTC offset? I saw on a Suse documentation that someth…

问题原文

原帖链接 · Philippe Gachoud · CC BY-SA 4.0

In Chile the case is very particular as the days of daylight saving changes are different a year from another...

Is there a function to get for given day at given UTC time the UTC offset?

I saw on a Suse documentation that something like zdump -v /usr/share/zoneinfo/Chile/Continental makes me enable to get all changings through years, but the job has to be done still... any command to do that?

Or/and is there a function with a given date and time from given timezone to UTC? And its reverse?

How does linux handle these changes? didn't find more documentation than Suse one.

已采纳解答

原帖链接 · Eduardo Trápani · CC BY-SA 4.0

You can use the date command. You set the timezone and then specify the date and time. The command will return that time with the -03 or -04, so you will know if DST was in effect.

For example, for Chile/Continental:

Before DST change this year:

$ TZ=Chile/Continental date --date='2020-04-03 11:00 +00'
Fri Apr  3 11:00:00 -03 2020

After DST change this year:

$ TZ=Chile/Continental date --date='2020-04-06 11:00 +00'
Mon Apr  6 11:00:00 -04 2020

To undo that, just set TZ to UTC and change the offset:

$ TZ=UTC date --date='2020-04-03 11:00 -04'

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-06-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。