Does django mess up with python's datetime? -
i have file check it's creation time using ctime. here snippet of code (not complete, important part):
import time import pytz import os datetime import datetime myfile = somewhere myfile_ctime = os.path.getctime(myfile) d = datetime.strptime(time.ctime(myfile_ctime), '%a %b %d %h:%m:%s %y') # d here tue mar 25 00:33:40 2014 example ny = pytz.timezone("america/new_york") d_ny = ny.localize(d) mytz = pytz.timezone(my_tz_whatever) myd = d_ny.astimezone(mytz) final_date = myd.strftime('%y-%m-%d %h:%m:%s') print(final_date + "some string") # 2014-03-25 01:33:40some string, correctly timezone. when run simple python script, ok. when run same code inside function in templatetags/myfile.py renders template in django app, when trying date time.ctime(myfile_ctime), tue mar 25 04:33:40 instead of tue mar 25 00:33:40 snippet above (the code the same in standalone script , in django - , concatenate date string).
my question is: i'm using python standard libraries, same snippet of code in both places, reading same file in same environment. why difference? settings in settings.py mangles up in standard libraries? being in django environment changes how standard libraries should work? why when calling standalone works should?
(i'm behind apache, don't know if relevant)
make sure of time zone settings in settings.py, more info django time zone settings, check page: https://docs.djangoproject.com/en/1.6/ref/settings/#time-zone
Comments
Post a Comment