【发布时间】:2012-09-23 08:28:41
【问题描述】:
这应该很简单,但我在 Python 中无法完全弄清楚。 我想要一个函数,它接受两个参数,一个 UTC 时间(以秒为单位)和一个 zoneinfo name(如 'Europe/Vienna'),并以秒为单位返回与本地时间的偏移量和该时间点的 UTC。
在 C 中应该是:
/* ... code to to set local time to the time zone I want to compare against,
not shown here. Then call function below to get difference vs localtime.
Hardly an ideal solution,
but just to demonstrate what I want in a "lingua franca" (C): */
int get_diff_vs_localtime(const time_t original_utc_time)
{
struct tm* ts;
ts = localtime(&original_utc_time);
return mktime(ts) - original_utc_time;
}
我想我的问题真的可以归结为:“给定 Olson timezone(例如 'Europe/Stockholm')和 UTC 时间,当地时间是多少?
【问题讨论】:
-
我召唤@JonSkeet 的力量!
-
我查看了您提供的链接(针对其他 SO 问题)。当心他们都没有正确处理与 DST 相关的问题。
-
@J.F.Sebastian,你很有野心。你的意思是他们都没有或只有一些?
标签: python date timezone pytz python-dateutil