Created
May 11, 2016 08:20
-
-
Save geoffreybauduin/20477596f0013f46b87cd0cbaa310ce2 to your computer and use it in GitHub Desktop.
Python datetime localizing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python 2.7.6 (default, Jun 22 2015, 17:58:13) | |
[GCC 4.8.2] on linux2 | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> import datetime | |
>>> import pytz | |
>>> dt = datetime.datetime(2002, 4, 7, 2, 30, 00) | |
>>> print dt | |
2002-04-07 02:30:00 | |
>>> dt = pytz.utc.localize(dt) | |
>>> print dt | |
2002-04-07 02:30:00+00:00 | |
>>> dt = pytz.utc.localize(dt) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "venv/local/lib/python2.7/site-packages/pytz/__init__.py", line 226, in localize | |
raise ValueError('Not naive datetime (tzinfo is already set)') | |
ValueError: Not naive datetime (tzinfo is already set) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment