python 好用的时间模块 arrow

发布时间:2025-04-18 01:44

Microsoft Outlook的时间管理模块 #生活常识# #时间管理建议# #时间管理工具推荐#

python 好用的时间模块 arrow

最新推荐文章于 2024-07-17 10:29:52 发布

天马行空波 于 2018-12-11 18:05:33 发布

转载自:诸葛老刘所有 https://blog.csdn.net/weixin_39791387/article/details/81566149 

In [1]: import arrow

In [2]: now = arrow.now('local')

In [3]: now

Out[3]: <Arrow [2018-11-06T12:23:53.594706+08:00]>

In [4]: now2 = arrow.now().to('local')

In [5]: now2

Out[5]: <Arrow [2018-11-06T12:24:18.191082+08:00]>

In [6]: now.format('YYYY-MM-DD')

Out[6]: '2018-11-06'

In [7]: now.format('YYYY-MM-DD HH:mm:ss')

Out[7]: '2018-11-06 12:23:53'

In [8]: now.shift(days=-1).format('YYYY-MM-DD')

Out[8]: '2018-11-05'

In [9]: now.shift(months=-1).format("YYYYMMDD")

Out[9]: '20181006'

In [10]: now.format('d')

Out[10]: '2'

In [11]: now.format('D')

Out[11]: '6'

In [12]: now.timestamp

Out[12]: 1541478233

In [13]: stamp = 1533890211

In [14]: arrow.get(stamp)

Out[14]: <Arrow [2018-08-10T08:36:51+00:00]>

In [15]: now.humanize()

Out[15]: '16 minutes ago'

In [16]: now.floor('day')

Out[16]: <Arrow [2018-11-06T00:00:00+08:00]>

In [17]: now.floor('month')

Out[17]: <Arrow [2018-11-01T00:00:00+08:00]>

In [18]: now.ceil('day')

Out[18]: <Arrow [2018-11-06T23:59:59.999999+08:00]>

In [19]: now.ceil('month')

Out[19]: <Arrow [2018-11-30T23:59:59.999999+08:00]>

In [20]: arrow.get('20181010', 'YYYYMMDD').format("YYYY-MM-DD")

Out[20]: '2018-10-10'

In [21]: start = arrow.get('2018-09-01','YYYY-MM-DD')

In [22]: end = arrow.get('2018-09-10','YYYY-MM-DD')

In [23]: [dt for dt in arrow.Arrow.range('day',start,end)]

Out[23]: [<Arrow [2018-09-01T00:00:00+00:00]>, <Arrow [2018-09-02T00:00:00+00:00]>, <Arrow [2018-09-03T00:00:00+00:00]>, <Arrow [2018-09-04T00:00:00+00:00]>, <Arrow [2018-09-05T00:00:00+00:00]>, <Arrow [2018-09-06T00:00:00+00:00]>, <Arrow [2018-09-07T00:00:00+00:00]>, <Arrow [2018-09-08T00:00:00+00:00]>, <Arrow [2018-09-09T00:00:00+00:00]>, <Arrow [2018-09-10T00:00:00+00:00]>]

In [25]: now.span('hour')

Out[25]: (<Arrow [2018-11-06T12:00:00+08:00]>, <Arrow [2018-11-06T12:59:59.999999+08:00]>)

In [26]: now.span('month')

Out[26]: (<Arrow [2018-11-01T00:00:00+08:00]>, <Arrow [2018-11-30T23:59:59.999999+08:00]>)

In [27]: now.span('week')

Out[27]: (<Arrow [2018-11-05T00:00:00+08:00]>, <Arrow [2018-11-11T23:59:59.999999+08:00]>)

In [28]: now.span('day')

Out[28]: (<Arrow [2018-11-06T00:00:00+08:00]>, <Arrow [2018-11-06T23:59:59.999999+08:00]>)

In [29]: now.format('YYYYMMDD HH:mm:ss')

Out[29]: '20181106 12:23:53'

In [30]: now.replace(hour=0, minute=30,second=0).format('YYYYMMDD HH:mm:ss')

Out[30]: '20181106 00:30:00'

网址:python 好用的时间模块 arrow https://www.yuejiaxmz.com/news/view/872742

相关内容

Python标准模块——gzip
Python Base64模块的使用
python serial模块的使用
python 智能家居控制模块
python中缓存模块的一些用法
python的常用日期处理datetime模块
python运用在生活!用Pillow模块给图片上加数字
【Python】15 个节省时间的 Jupyter 技巧
Python 开发者节省时间的 10 个方法
Python编程快速上手让繁琐工作自动化

随便看看