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.

pythonライブラリのzoneinfoとは

Posted at

はじめに

pythonでdatetimeライブラリを使用するときに見かけることがあるかもしれないzoneinfo、こんかいはこれが何なのか、どのように使われるのか、使用例とともにみていく。

じゃあzoneinfoってなに?

zoneinfoはIANAのタイムゾーンデータベースをサポートした具体的なタイムゾーン実装を提供します。
https://docs.python.org/ja/3/library/zoneinfo.html を参照)
IANAとは「Internet Assigned Numbers Authority」 の略でIPアドレスやドメイン名、の割り当てや標準化を行う組織のことです。つまりzoneinfoはIANAが管理している世界各地域の時間帯情報を収録したデータベースから時間データを持ってくることができることができるライブラリということになります。

実装例

sample.py
from datetime import datetime
from zoneinfo import ZoneInfo

dt = datetime(2020, 10, 31, 12)
print(dt)
LA_dt = dt = datetime(2020, 10, 31, 12, tzinfo=ZoneInfo("America/Los_Angeles"))
print(LA_dt)
TOKYO_dt = datetime(2020, 10, 31, 12, tzinfo=ZoneInfo("Asia/Tokyo"))
print(TOKYO_dt)

#実行結果
2020-10-31 12:00:00,
2020-10-31 12:00:00-07:00,
2020-10-31 12:00:00+09:00

実行結果から分かるようにオフセットが表示される。

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?