-
-
Save lqez/f5c83a47a483ffc1d849 to your computer and use it in GitHub Desktop.
utc-lize datetime vs time
This file contains hidden or 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
import pytz | |
import datetime | |
import time | |
s = "2015-01-01 12:34:56" | |
local = pytz.timezone("Asia/Seoul") | |
begin = datetime.datetime.now() | |
for _ in xrange(10000): | |
naive = datetime.datetime.strptime(s, "%Y-%m-%d %H:%M:%S") | |
local_dt = local.localize(naive, is_dst=None) | |
utc = local_dt.astimezone(pytz.utc) | |
print datetime.datetime.now() - begin | |
begin = datetime.datetime.now() | |
for _ in xrange(10000): | |
utc = time.gmtime(time.mktime(time.strptime(s, "%Y-%m-%d %H:%M:%S"))) | |
print datetime.datetime.now() - begin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
0:00:00.474197
0:00:00.204134