... ime オブジェクトを作成した場合も、aware となります。このモードでは、上の例は以下のようになります: from django.utils import timezone now = timezone . now () 警告 認識された datetime オブジェクトを扱うことは、必ずしも直感的ではありません。例えば、標準の da ... ださい。 注釈 Python の datetime.time オブジェクトは、 tzinfo 属性を持ちます。また PostgreSQL には、これに相当する time with time zone タイプがあります。ただし、PostgreSQL のドキュメントにあるとおり、このタイプは "不確かな有用性に導く特性を示しています"。 ... は timedelta 計算を通じて他の日時から作成されます。唯一アプリケーションのコード内でよく作成される datetime は現在の時刻で、 timezone.now() は自動的に適切な処理を行います。 デフォルトタイムゾーンとカレントタイムゾーン ¶ デフォルトタイムゾーン は、 TIME_ZON ... ... ime オブジェクトを作成した場合も、aware となります。このモードでは、上の例は以下のようになります: from django.utils import timezone now = timezone . now () 警告 認識された datetime オブジェクトを扱うことは、必ずしも直感的ではありません。例えば、標準の da ... ださい。 注釈 Python の datetime.time オブジェクトは、 tzinfo 属性を持ちます。また PostgreSQL には、これに相当する time with time zone タイプがあります。ただし、PostgreSQL のドキュメントにあるとおり、このタイプは "不確かな有用性に導く特性を示しています"。 ... は timedelta 計算を通じて他の日時から作成されます。唯一アプリケーションのコード内でよく作成される datetime は現在の時刻で、 timezone.now() は自動的に適切な処理を行います。 デフォルトタイムゾーンとカレントタイムゾーン ¶ デフォルトタイムゾーン は、 TIME_ZON ... ... e.datetime を返します。 UTC オフセットに対応しています。もし value がそれを記述している場合、結果の tzinfo 属性は datetime.timezone インスタンスになります。 parse_duration ( value ) [ソース] ¶ 文字列を解析し、 datetime.timedelta を返します。 データは、 " ... 合は、 allow_unicode=True を渡します。例えば: >>> slugify ( "你好 World" , allow_unicode = True ) '你好-world' django.utils.timezone ¶ get_fixed_timezone ( offset ) [ソース] ¶ UTCからの固定オフセットを持つタイムゾーンを表す tzinfo インスタンスを返します。 ... datetime.timedelta または整数の分数です。UTCより東のタイムゾーンには正の値を、西には負の値を使用してください。 get_default_timezone () [ソース] ¶ デフォルトのタイムゾーン を表す tzinfo インスタンスを返します。 get_default_timezone_name () [ソース] ¶ デフ ... ... e.datetime を返します。 UTC オフセットに対応しています。もし value がそれを記述している場合、結果の tzinfo 属性は datetime.timezone インスタンスになります。 parse_duration ( value ) [ソース] ¶ 文字列を解析し、 datetime.timedelta を返します。 データは、 " ... 合は、 allow_unicode=True を渡します。例えば: >>> slugify ( "你好 World" , allow_unicode = True ) '你好-world' django.utils.timezone ¶ get_fixed_timezone ( offset ) [ソース] ¶ UTCからの固定オフセットを持つタイムゾーンを表す tzinfo インスタンスを返します。 ... datetime.timedelta または整数の分数です。UTCより東のタイムゾーンには正の値を、西には負の値を使用してください。 get_default_timezone () [ソース] ¶ デフォルトのタイムゾーン を表す tzinfo インスタンスを返します。 get_default_timezone_name () [ソース] ¶ デフ ... ... 確認してください。 / $ python manage.py shell ...\> py manage.py shell >>> import datetime >>> from django.utils import timezone >>> # create a Question instance with pub_date 30 days in the future >>> future_question = Question ( pub_date = timezone ... ファイルに次のコードを書きます。 polls/tests.py ¶ import datetime from django.test import TestCase from django.utils import timezone from .models import Question class QuestionModelTests ( TestCase ): def test_was_published_recently_with_future_question ( ... self ): """ was_published_recently() returns False for questions whose pub_date is in the future. """ time = timezone . now () + datetime . timedelta ( days = 30 ) future_question = Question ( pub_date = time ) self . assertIs ( future_ques ... ... 確認してください。 / $ python manage.py shell ...\> py manage.py shell >>> import datetime >>> from django.utils import timezone >>> # create a Question instance with pub_date 30 days in the future >>> future_question = Question ( pub_date = timezone ... ファイルに次のコードを書きます。 polls/tests.py ¶ import datetime from django.test import TestCase from django.utils import timezone from .models import Question class QuestionModelTests ( TestCase ): def test_was_published_recently_with_future_question ( ... self ): """ was_published_recently() returns False for questions whose pub_date is in the future. """ time = timezone . now () + datetime . timedelta ( days = 30 ) future_question = Question ( pub_date = time ) self . assertIs ( future_ques ... ... delAdmin の属性) actions_on_top (ModelAdmin の属性) actions_selection_counter (ModelAdmin の属性) activate() (django.utils.timezone モジュール) (django.utils.translation モジュール) acycle_key() (backends.base.SessionBase のメソッド) add template filter ... (Field のメソッド) dbshell django-admin command dbshell コマンドラインオプション -- --database deactivate() (django.utils.timezone モジュール) (django.utils.translation モジュール) deactivate_all() (django.utils.translation モジュール) DEBUG setting deb ... o.utils.log module django.utils.module_loading module django.utils.safestring module django.utils.text module django.utils.timezone module django.utils.translation module django.views module django.views.decorators.cache module django.views.decorators.ca ... ... delAdmin の属性) actions_on_top (ModelAdmin の属性) actions_selection_counter (ModelAdmin の属性) activate() (django.utils.timezone モジュール) (django.utils.translation モジュール) acycle_key() (backends.base.SessionBase のメソッド) add template filter ... (Field のメソッド) dbshell django-admin command dbshell コマンドラインオプション -- --database deactivate() (django.utils.timezone モジュール) (django.utils.translation モジュール) deactivate_all() (django.utils.translation モジュール) DEBUG setting deb ... o.utils.log module django.utils.module_loading module django.utils.safestring module django.utils.text module django.utils.timezone module django.utils.translation module django.views module django.views.decorators.cache module django.views.decorators.ca ... ... ect() get_context_object_name() get_context_data() get() render_to_response() 例 myapp/views.py : from django.utils import timezone from django.views.generic.detail import DetailView from articles.models import Article class ArticleDetailView ( DetailVie ... Article def get_context_data ( self , ** kwargs ): context = super () . get_context_data ( ** kwargs ) context [ "now" ] = timezone . now () return context 例 myapp/urls.py : from django.urls import path from article.views import ArticleDetailView urlpat ... yset() get_context_object_name() get_context_data() get() render_to_response() Example views.py : from django.utils import timezone from django.views.generic.list import ListView from articles.models import Article class ArticleListView ( ListView ): mod ... ... 強く推奨 します。 The Django 3.2.x series is the last to support Python 3.6 and 3.7. Django 4.0 の新機能 ¶ zoneinfo default timezone implementation ¶ The Python standard library's zoneinfo is now the default timezone implementation in Django. This is the ... next step in the migration from using pytz to using zoneinfo . Django 3.2 allowed the use of non- pytz time zones. Django 4.0 makes zoneinfo the default implementation. Support for pytz is now deprecated and will be removed in Django ... alongside Django if you are using Python 3.8. The move to zoneinfo should be largely transparent. Selection of the current timezone, conversion of datetime instances to the current timezone in forms and templates, as well as operations on aware datetimes ... 2026年10月08日