After playing Gae for a while, I suddenly found that in the Python application of gae, the obtained time is UTC time, But I clearly remember that the obtained time was local time !!
An application should have a time reference point. Most applications should use local time as the reference point.
In python2.5:
>>> Import datetime
>>> Datetime. datetime. Now ()
Datetime. datetime (2009, 5, 26, 20, 18, 2, 593000)
>>> Datetime. datetime. Now (8)
Traceback (most recent call last ):
File "<interactive input>", line 1, in <module>
Typeerror: tzinfo argument must be none or of a tzinfo subclass, not type 'int'
It can be seen that the passed TZ parameter must be a subclass of datetime. tzinfo or none. However, datetime. tzinfo is an abstract class and cannot be instantiated.
Python third-party packages are easy to handle:
>>> Import pytz
>>> Import datetime
>>> Datetime. datetime. Now ()
Datetime. datetime (2009, 5, 26, 20, 23, 12,109 000)
>>> Datetime. datetime. Now (pytz. UTC)
Datetime. datetime (2009, 5, 26, 12, 23, 23,500 000, tzinfo = <UTC>)
>>> Datetime. datetime. Now (pytz. timezone (pytz. country_timezones ('cn') [2])
Datetime. datetime (2009, 5, 26, 20, 24, 9, 296000, tzinfo = <dsttzinfo 'Asia/chongqing' CST + 8:00:00 STD>)
>>> Pytz. country_timezones ('cn ')
['Asia/Shanghai', 'Asia/harbin', 'Asia/Chongqing ', 'Asia/Urumqi', 'Asia/kashgar']
>>>
It is mainly the TZ parameter construction of datetime. datetime. Now (Tz.
To reduce the volume of a third-party package, compress the package and add it to SYS. Path.
For example:
The pytzpy2.5-2006.zip contains the pytz folder
Pytz_path = r 'd:/applit/Python/pytzpy2.5-2006.zip'
Import sys
SYS. insert (0, pytz_path)