如何将钟摆转换为datetime.datetime类型? [英] How to convert pendulum to datetime.datetime type?

查看:93
本文介绍了如何将钟摆转换为datetime.datetime类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在系统摆锤v1.4的当前部分中使用了摆锤v1.4,但由于摆弄钳,它会导致 https://github.com/sdispater/pendulum/issues/214

In current part of system pendulum v1.4 is used, but with croniter it causing error described in https://github.com/sdispater/pendulum/issues/214

这与datetime.datetime类型兼容,我仍然必须保持钟摆v1.4。

This works fine with datetime.datetime type and i still have to stay with pendulum v1.4.

所以我正在寻找一种解决方案,该方法如何有效地将钟摆转换为datetime.datetime类型?

So i am looking for solution how to efficiently to convert pendulum to datetime.datetime type ?

已经尝试将摆锤格式化为字符串并使用dateutil.parser进行解析。

Already tried formatting pendulum as string and parsing using dateutil.parser.

推荐答案

对此的另一种看法:

>>> from datetime import datetime
>>> import pendulum
>>> datetime.fromtimestamp(pendulum.now().timestamp())
datetime.datetime(2019, 3, 20, 16, 32, 24, 172283)

但是,实际上没有必要:摆锤 DateTime 继承自 datetime.datetime ,因此与stdlib的 datetime 一起工作的任何代码也应正常工作。

But, actually, there is no need: pendulum's DateTime inherits from datetime.datetime, so any code working with stdlib's datetime's should work as well.

这篇关于如何将钟摆转换为datetime.datetime类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆