2024-05-16 20:28:54 发布
网友
在系统的当前部分中,使用的是单摆v1.4,但在croniter中,它会导致https://github.com/sdispater/pendulum/issues/214中描述的错误
这和日期时间。日期时间我还是得用钟摆v1.4。在
所以我在寻找解决方案,如何有效地将摆锤转换为日期时间。日期时间类型?在
已经尝试过将钟摆格式化为字符串并使用dateutil.parser. 在
另一种说法是:
>>> from datetime import datetime >>> import pendulum >>> datetime.fromtimestamp(pendulum.now().timestamp()) datetime.datetime(2019, 3, 20, 16, 32, 24, 172283)
但是,实际上,没有必要:pendulum的DateTime继承自datetime.datetime,因此任何使用stdlib的datetime的代码也应该可以工作。在
pendulum
DateTime
datetime.datetime
datetime
我也找不到钟摆的助手。所以,回到基本点:
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文档建议日期util.tz而不是pytz作为IANA时区提供者。在
另一种说法是:
但是,实际上,没有必要:
pendulum
的DateTime
继承自datetime.datetime
,因此任何使用stdlib的datetime
的代码也应该可以工作。在我也找不到钟摆的助手。所以,回到基本点:
注意dateutil的用法。对于python3.6,tzinfo文档建议日期util.tz而不是pytz作为IANA时区提供者。在
相关问题 更多 >
编程相关推荐