Skip to content

Instantly share code, notes, and snippets.

@neoshrew
Last active September 5, 2016 14:24
Show Gist options
  • Save neoshrew/4bc4699fd0c618a88292aca427dd5ebe to your computer and use it in GitHub Desktop.
Save neoshrew/4bc4699fd0c618a88292aca427dd5ebe to your computer and use it in GitHub Desktop.
import dateutil.parser, datetime, pytz
def printy(thing):
print repr(thing)
x = datetime.datetime.utcnow()
printy(x)
x = pytz.utc.localize(x)
printy(x)
x = x.isoformat()
printy(x)
x = dateutil.parser.parse(x)
printy(x)
x = x.isoformat()
printy(x)
print "\n\n"
x = datetime.datetime.now()
printy(x)
x = pytz.timezone('Europe/London').localize(x)
printy(x)
x = x.isoformat()
printy(x)
x = dateutil.parser.parse(x)
printy(x)
x = x.isoformat()
printy(x)
print "\n\n"
x = datetime.datetime.now()
printy(x)
x = pytz.timezone('US/Hawaii').localize(x)
printy(x)
x = x.isoformat()
printy(x)
x = dateutil.parser.parse(x)
printy(x)
x = x.isoformat()
printy(x)
datetime.datetime(2016, 9, 5, 14, 24, 4, 135526)
datetime.datetime(2016, 9, 5, 14, 24, 4, 135526, tzinfo=<UTC>)
'2016-09-05T14:24:04.135526+00:00'
datetime.datetime(2016, 9, 5, 14, 24, 4, 135526, tzinfo=tzutc())
'2016-09-05T14:24:04.135526+00:00'
datetime.datetime(2016, 9, 5, 15, 24, 4, 136024)
datetime.datetime(2016, 9, 5, 15, 24, 4, 136024, tzinfo=<DstTzInfo 'Europe/London' BST+1:00:00 DST>)
'2016-09-05T15:24:04.136024+01:00'
datetime.datetime(2016, 9, 5, 15, 24, 4, 136024, tzinfo=tzoffset(None, 3600))
'2016-09-05T15:24:04.136024+01:00'
datetime.datetime(2016, 9, 5, 15, 24, 4, 151031)
datetime.datetime(2016, 9, 5, 15, 24, 4, 151031, tzinfo=<DstTzInfo 'US/Hawaii' HST-1 day, 14:00:00 STD>)
'2016-09-05T15:24:04.151031-10:00'
datetime.datetime(2016, 9, 5, 15, 24, 4, 151031, tzinfo=tzoffset(None, -36000))
'2016-09-05T15:24:04.151031-10:00'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment