转载自:诸葛老刘所有 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'