Skip to content

Instantly share code, notes, and snippets.

@aodag
Created April 11, 2015 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aodag/0cee079e1a0a9c574f5d to your computer and use it in GitHub Desktop.
Save aodag/0cee079e1a0a9c574f5d to your computer and use it in GitHub Desktop.
UTC表記の日時をパースしてローカルタイムゾーンで表示するまで

>>> d = dateutil.parser.parse('2015-01-01 00:00:00+00') >>> d datetime.datetime(2015, 1, 1, 0, 0, tzinfo=tzutc()) >>> d.astimezone(dateutil.tz.tzlocal()) datetime.datetime(2015, 1, 1, 9, 0, tzinfo=tzlocal()) >>> d.astimezone(dateutil.tz.tzlocal()).strftime('%c') '01/01/15 09:00:00' >>> d.astimezone(dateutil.tz.tzlocal()).strftime('%z') '+0900' >>> d.astimezone(dateutil.tz.tzlocal()).strftime('%X') '09:00:00'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment