Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
どうやら、pytz.UTC.localize(datetime.datetime.now())現在の時刻を他の「ナイーブな」時刻オブジェクトと比較する前に実行する必要があります。
pytz.UTC.localize(datetime.datetime.now())
何故ですか?現在の時刻は特定のタイムゾーンに関連していませんか?
>>> datetime.datetime.now().utcoffset() is None True
関数は確かにnow単純なオブジェクトを返します。これには、ロケール設定に従って入力された日付と時刻のフィールド値が含まれています。そのため、個別utcnowに提供されています。常にUTCフィールド値を提供します(まだ単純ですが)。
now
utcnow