有没有一种优雅的方式来显示另一个时区的当前时间?
我想拥有一般的精神:
cur = <Get the current time, perhaps datetime.datetime.now()>
print("Local time {}".format(cur))
print("Pacific time {}".format(<something like cur.tz('PST')>))
print("Israeli time {}".format(<something like cur.tz('IST')>))
Run Code Online (Sandbox Code Playgroud) 我有变量,其中包含UTC时间类型为datetime.time的时间,我希望它转换为其他时区.
我们可以在datetime.datetime实例中转换时区,如此SO链接所示 - 如何在Python中将本地时间转换为UTC?.我无法弄清楚如何在datetime.time实例中转换时区.我不能使用astimezone,因为datetime.time没有这个方法.
例如:
>>> t = d.datetime.now().time()
>>> t
datetime.time(12, 56, 44, 398402)
>>>
Run Code Online (Sandbox Code Playgroud)
我需要UTC格式的't'.