我知道我可以把一个datetime.datetime
转换成钟摆
from datetime import datetime,timezone
import pendulum
a = datetime(2021,6,1,tzinfo=timezone.utc)
b = pendulum.instance(a)
b.tzinfo.name # the presence of the attribute 'name' means it's a pendulum timezone
type(b.tzinfo) # pendulum.tz.timezone.FixedTimezone
但是我有一个独立的datetime.tzinfo
,可以把它转换成pendulum.tz.timezone.*
a = timezone.utc # well, imagine that it can be any tzinfo
b = pendulum.xxxxx(a) # that gives tome pendum.tz.timezone class
有这样的方法吗
查看} ,您可以使用该函数将
pendulum.instance()
的实现,您可以看出它依赖于一个“私有”函数^{tzinfo
转换为钟摆的时区。以_
下划线开头的方法/函数通常表示它们不构成公共API的一部分,但函数就在那里在
tzinfo=timezone.utc
的情况下,pendulum.instance()
将tzinfo对象转换为小时偏移量,并将其传递给pendulum.datetime
,后者将使用pendulum._safe_timezone()
将其转换为pendulum.tz.timezone.FixedTimeZone
。但是_safe_timezone()
也接受正则datetime.tzinfo
作为输入相关问题 更多 >
编程相关推荐