在我们的Django的日志里,显示的时间要比北京时间晚8个小时。
^Croot@iZ2ze4r3b4xczuujolp68uZ:~/HelloWorld# python3 manage.py runserver 0.0.0.0:8006
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
June 06, 2020 - 09:11:16
Django version 3.1a1, using settings 'HelloWorld.settings'
Starting development server at http://0.0.0.0:8006/
Quit the server with CONTROL-C.
[06/Jun/2020 09:11:18] "GET /runoob HTTP/1.1" 301 0
[06/Jun/2020 09:11:18] "GET /runoob/ HTTP/1.1" 200 14
[06/Jun/2020 09:11:20] "GET /runoob/ HTTP/1.1" 200 14
[06/Jun/2020 09:17:52] "GET /runoob/ HTTP/1.1" 200 14
[06/Jun/2020 12:31:23] "GET /runoob/ HTTP/1.1" 200 14
[06/Jun/2020 12:31:26] "GET /runoob/ HTTP/1.1" 200 14
[06/Jun/2020 12:31:37] "GET /runoob/ HTTP/1.1" 200 14
[06/Jun/2020 12:31:38] "GET /runoob/ HTTP/1.1" 200 14
[06/Jun/2020 12:31:40] "GET /runoob/ HTTP/1.1" 200 14
[06/Jun/2020 12:31:41] "GET /runoob/ HTTP/1.1" 200 14
[06/Jun/2020 12:31:46] "GET /runoob/ HTTP/1.1" 200 14
[06/Jun/2020 12:31:47] "GET /runoob/ HTTP/1.1" 200 14
[06/Jun/2020 12:31:47] "GET /runoob/ HTTP/1.1" 200 14
可以修改项目工程里的settings.py文件中的TIME_ZONE
和USE_TZ
。
如果USE_TZ设置为True时,Django会使用系统默认设置的时区,即America/Chicago,此时的TIME_ZONE不管有没有设置都不起作用。
如果USE_TZ 设置为False,而TIME_ZONE设置为None,则Django还是会使用默认的America/Chicago时间。
若TIME_ZONE设置为其它时区的话,则还要分情况,如果是Windows系统,则TIME_ZONE设置是没用的,Django会使用本机的时间。如果为其他系统,则使用该时区的时间,入设置USE_TZ = False, TIME_ZONE = ‘Asia/Shanghai’, 则使用上海的UTC时间。
修改完重启服务,就发现日志的时间变了。