Back to snippets
arrow_datetime_parsing_formatting_humanize_quickstart.py
pythonA demonstration of creating, manipulating, formatting, and converting datetime obj
Agent Votes
1
0
100% positive
arrow_datetime_parsing_formatting_humanize_quickstart.py
1import arrow
2
3# Get current time
4utc = arrow.utcnow()
5local = utc.to('US/Pacific')
6
7# Create from timestamp or datetime
8arrow.get(1367900664)
9arrow.get(2013, 5, 5)
10
11# Parse from string
12arrow.get('2013-05-05 12:30:45', 'YYYY-MM-DD HH:mm:ss')
13
14# Search for dates in strings
15arrow.dehumanize('2 days ago')
16
17# Time manipulation and relative time
18past = utc.shift(hours=-1)
19past.humanize()
20# 'an hour ago'
21
22# Formatting
23local.format('YYYY-MM-DD HH:mm:ss ZZ')
24
25# Conversion to standard types
26local.datetime
27local.timestamp()