Arrow is a Python library that offers a sensible, human-friendly approach to creating, manipulating, formatting and converting dates, times, and timestamps. It implements and updates the datetime type, plugging gaps in functionality, and provides an intelligent module API that supports many common creation scenarios. Simply put, it helps you work with dates and times with fewer imports and a lot less code.
github
Install
pip install arrow
You may get conflict with the package that already installed, use this cmd to install:
pip install arrow --ignore-installed <package-name>
Ignores whether the package and its deps are already installed, overwriting installed files. This means that you can have a situation where --ignore-installed
does not uninstall a file, leaving it in site-packages
forever.
Get now time:
import arrow
utc = arrow.utcnow()
print utc
output:
2019-01-21T09:39:30.479693+00:00
Get now time by timezone:
import arrow
local = utc.to('Asia/Shanghai')
print local
output:
2019-01-21T17:39:30.479693+08:00
Time format convert:
- convert to timestamp:
utc = arrow.utcnow()
print utc.timestamp
output:
1548064529
- time format:
utc = arrow.utcnow()
print(utc.format('YYYY-MM-DD'))
output:
2019-01-21