在系统的当前部分中,使用的是v1.4版,但对于croniter,它会导致https://github.com/sdispater/pendulum/issues/214中描述的错误
这在datetime.datetime类型下工作得很好,我仍然需要继续使用Pandulumv1.4。
所以我正在寻找如何有效地将钟摆转换为datetime.datetime类型的解决方案?
我已经尝试将pendulum格式化为字符串,并使用dateutil.parser进行解析。
发布于 2019-03-20 21:35:09
另一种观点是:
>>> from datetime import datetime
>>> import pendulum
>>> datetime.fromtimestamp(pendulum.now().timestamp(), pendulum.tz.UTC)
datetime.datetime(2021, 1, 12, 11, 41, 32, 387753, tzinfo=Timezone('UTC'))通常不需要这样做,因为pendulum的DateTime继承自datetime.datetime,任何使用标准库的datetime的代码也应该可以使用钟摆的。
发布于 2019-02-21 07:06:48
我也找不到Pendulum的助手。所以,让我们回到基本问题:
import datetime as dt
tz_info = dateutil.tz.gettz(zone_name)
pend_time = pendulum.datetime(...)
dt_time = dt.datetime(
pend_time.year,
pend_time.month,
pend_time.day,
pend_time.hour,
pend_time.minute,
pend_time.second,
pend_time.microsecond,
).astimezone(tz_info)注意dateutil的用法。从Python3.6开始,tzinfo文档建议使用dateutil.tz而不是pytz作为IANA时区提供程序。
发布于 2021-05-25 00:46:54
钟摆对象具有受保护的_datetime成员:
import pendulum
p = pendulum.now()
p._datetime这将为您提供如下内容
datetime.datetime(2021, 5, 24, 12, 44, 11, 812937, tzinfo=<TimezoneInfo [America/New_York, EDT, -4:00:00, DST]>)https://stackoverflow.com/questions/54028325
复制相似问题