0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Django】タイムゾーン修正方法

Posted at

Djangoのタイムゾーンを日本に変更する方法

デフォルトではUTCが設定されているため、
日本に変更する必要がある

settings.pyを修正する

設定方法は、settings.pyを修正することで可能です。

対象は以下文言です

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

以下に修正します

LANGUAGE_CODE = 'ja'

TIME_ZONE = 'Asia/Tokyo'

適用確認

python manage.py shell

shellを起動し、現在時刻を確認します

以下ファイル修正前
In [1]: from datetime import datetime

In [2]: print(datetime.now())
2022-06-13 12:43:06.603059

以下ファイル修正後
In [1]: from datetime import datetime

In [2]: print(datetime.now())
2022-06-13 21:44:31.749582

時刻が正しいものに変わっていることがわかります

以上です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?