1
23
它是
hard to get a reliable answer
. 依靠像这样的东西
(变量
However, there are some issues with the above approaches. 这个
Also there's nothing to stop the user copying the right timezone file there instead of creating a symlink. One possibility to get round this (which seems to work on Debian, RedHat and OpenBSD) is to compare the contents of the /etc/localtime file to the files under /usr/share/zoneinfo, and see which ones match:
当然了 缺点 is that this will tell you all timezones that are identical to the current one. (That means identical in the full sense - not just "currently at the same time", but also "always change their clocks on the same day as far as the system knows".)
您的最佳选择可能是结合上述方法:使用
(And I have no idea whether any of the above applies on AIX...) |
2
5
没有
标准
C或C++函数用于此。然而,GNU LIBC有一个扩展。它的
这意味着如果使用一个函数来填充
Also many systems have a
不完全是你要的,但接近… |
3
5
I've been working on a free, open source C++11/14 library 它用一行代码来解决这个问题:
It is meant to be portable across all recent flavors of Linux, macOS and Windows. For me this program outputs:
如果你 download 这个图书馆不适合你, bug reports 欢迎光临。 |
4
4
Pretty late in the day, but I was looking for something similar and found that ICU library has the provision to get the Olson timezone ID: http://userguide.icu-project.org/datetime/timezone 它现在安装在大多数Linux发行版上(安装libicu dev包或等效软件包)。代码:
并获得缩写/ POSIX时区名称(也应该在Windows上工作):
|
5
4
我看到两个主要的Linux案例:
此外,Solaris应该有一个/etc/timezone文件,其中包含一行,如:tz=us/mountain 基于以上,这里有一些直的C,我相信回答了OP的问题。我在Ubuntu、Centos(Red Hat)和Solaris(Bonus)上测试过它。
|
6
2
I liked the post made by psmears and implemented this script to read the first output of the list. Of course there must have more elegant ways of doing this, but there you are...
在我的巴西软呢帽12中,它返回:
做我所需要的。
谢谢你,psmears |
7
2
FWIW,Rhel/Fedora/Centos已经
|
8
2
这是适用于大多数Linux版本的代码。
|
9
0
根据
this
佩奇,如果你
这能给你所需要的信息吗? |
10
0
如果您想便携式,那么只能在内部使用gmt。由于多用户继承,*nix系统时钟通常是格林尼治标准时间,没有系统范围的时区-因为连接到系统的不同用户可能生活在不同的时区。
用户特定的时区反映在
|
11
0
libc在以下情况下访问olson数据库:
tzset
is called, and uses simplified time zones afterwards.
起初
systemd
看着
如果你可以生活在没有象征性的名字下,
parsing
这个
|
12
0
Since tzselect was not mentioned by anyone and you do need a nearly goof-proof solution, work with what Olson did. Get the tzcode and tzdata files from elsie, plus tab files.
In March 2017, the correct location to download from would be
ftp://ftp.iana.org/tz/releases
(下载)
Then get tzselect.ksh from the glibc download. Then you can see how to reverse engineer timezones. One sticking point: you WILL sometimes have to ask what country and city the linux box is in. You can serialize that data if you want, and then verify it against the timezone data you can find. There is no way to do this reliably all the time without the possibility of user intervention, for example, as part of program installation. 祝亚利桑那州和西印第安纳州好运……希望您的代码可以在其他地方运行。 |
mikro098 · 如何解析ISO8061到无时区的日期 6 年前 |
Alexander Staroselsky · 替换时区 6 年前 |
Luiz · 在PostgreSQL中使用时区正确处理时间 6 年前 |
Thomas · 在C中使用夏令时处理时区# 6 年前 |
Yasitha · 我正在尝试使用GMT值获取时区名称 6 年前 |