1
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?

Pythonで「日付と時刻の情報を指定してインスタンスを生成する」の動作を確認してみた

Posted at

概要

Pythonで「日付と時刻の情報を指定してインスタンスを生成する」の動作を確認してみました。
以下のページを参考にしました。

実装

以下のファイルを作成しました。

sample.py
import datetime
dt1 = datetime.datetime(2020, 7, 21)
print(dt1)
dt2 = datetime.datetime(2020, 7, 21, 6, 12, 30, 551)
print(dt2)
tokyo_tz = datetime.timezone(datetime.timedelta(hours=9))
dt3 = datetime.datetime(2020, 7, 21, 6, 12, 30, 551, tokyo_tz)
print(dt3)

import datetime
d = datetime.date(2020, 7, 21)
print(d)

import datetime
t1 = datetime.time(6, 12, 30, 551)
print(t1)
tokyo_tz = datetime.timezone(datetime.timedelta(hours=9))
t2 = datetime.time(6, 12, 30, 551, tokyo_tz)
print(t2)

import datetime
print(datetime.datetime(2020, 7, 21, 6, 12, 30, 551))
print(datetime.date(2019, 12, 9))
print(datetime.time(23, 18, 45, 31112))
tokyo_tz = datetime.timezone(datetime.timedelta(hours=9))
print(datetime.datetime(2020, 7, 21, 6, 12, 30, 551, tokyo_tz))
ny_tz = datetime.timezone(datetime.timedelta(hours=-4))
print(datetime.datetime(2020, 7, 21, 6, 12, 30, 551, ny_tz))

以下のコマンドを実行しました。

$ python3 sample.py 
2020-07-21 00:00:00
2020-07-21 06:12:30.000551
2020-07-21 06:12:30.000551+09:00
2020-07-21
06:12:30.000551
06:12:30.000551+09:00
2020-07-21 06:12:30.000551
2019-12-09
23:18:45.031112
2020-07-21 06:12:30.000551+09:00
2020-07-21 06:12:30.000551-04:00

まとめ

何かの役に立てばと。

1
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
1
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?