<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,Arial,'Hiragino Sans GB','Microsoft YaHei',simsun;vertical-align:baseline;color:rgb(93,93,93);background-color:rgb(255,255,255);"> ![](http://img50.lidatong.com.cn//uploads/allimg/c20201216/22b14db05488fe258cc928d7fce6826a.gif) <p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">![](http://img50.lidatong.com.cn//uploads/allimg/c20201216/7d8663ed7fc8a4a1ae4d25eb9d7a3a76.gif) <p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">内建的 datetime 模块<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">![](http://img50.lidatong.com.cn//uploads/allimg/c20201216/31780cea38a11b389e6b2a1306b9709b.gif) <p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">![](http://img50.lidatong.com.cn//uploads/allimg/c20201216/f60c7d357b82f5b7bb0c8b1039b17a72.gif) <p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">让我们看看其他库是如何处理这种转换的。<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">Dateutil<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">![](http://img50.lidatong.com.cn//uploads/allimg/c20201216/0dcce82cf2784f9a64cf7ec71c775c00.gif) <p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">![](http://img50.lidatong.com.cn//uploads/allimg/c20201216/32345ee16cd8ae0fbf28e01cbc1b5500.gif) <p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">通过 Arrow datetime 类的实例,你可以访问 Arrow 的其他有用方法。例如,它的<code style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;">humanize()方法将日期时间翻译成人类可读的短语,就像这样:<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">![](http://img50.lidatong.com.cn//uploads/allimg/c20201216/1d61b6ee66c6918d81b76f5de38e6751.gif) <p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">![](http://img50.lidatong.com.cn//uploads/allimg/c20201216/fd14f63e9f5f26000cb8a089b34dab4a.gif) <p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">由于 Maya 与 datetime 库中很多有用的方法重叠,因此它可以使用 MayaDT 类的实例执行诸如使用?<code style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;">slang_time()?方法将时间偏移量转换为纯文本语言,并将日期时间间隔保存在单个类的实例中。以下是如何使用 Maya 将日期时间表示为人类可读的短语:<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">![](http://img50.lidatong.com.cn//uploads/allimg/c20201216/5399962c535a509c44b55993b0e6e6ea.gif) <p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">现在,你有了一个 datetime 对象 d_t,你可以使用 Delorean 来做一些事情,例如将日期时间转换为美国东部时区:<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">![](http://img50.lidatong.com.cn//uploads/allimg/c20201216/91015a29ceadb25b9cf86892d335f742.gif) <p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">![](http://img50.lidatong.com.cn//uploads/allimg/c20201216/3d240c7a7b02fe8ba74d5bf3da05f030.gif) <p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">欢迎大家关注我的博客或者公众号:https://home.cnblogs.com/u/Python1234/ Python学习交流<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">欢迎大家加入我的千人交流学习群:125240963<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">![](http://img50.lidatong.com.cn//uploads/allimg/c20201216/daab5ee86855f2b567955ddc2aa64c9c.gif) (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|