Django time zone

If Django has the Time Zone function turned on, all storage and internal processing, even direct print display, are all UTC. Only when the form input / rendering output is performed through the template, UTC local time conversion will be performed.

Therefore, I suggest that when processing time in the background, it is best to use UTC completely, and do not consider the existence of local time. When displaying the time, avoid manual conversion and try to use the Django template system instead.

datetime.datetime.now () The output is always local time and has nothing to do with the configuration.


Turn on USE_TZ = True TIME_ZONE No matter what the setting is, insert the database is the time of the eighth district, the database will add 8 hours to the original time of the project
Setting USE_TZ = False and TIME_ZONE = 'UTC' is equivalent to USE_TZ = True.
When querying, Django will take the time +8 to the database to check, and return the data minus 8 in the database

When USE_TZ = False and TIME_ZONE = 'Asia / Shanghai', the current time will be inserted, which is the datetime.datetime.now () in the project
When querying, what time value is passed in, the query corresponds to the database, and the time returned is also the time in the East Eight District 

Guess you like

Origin www.cnblogs.com/weidaijie/p/12753854.html
Recommended