0
1

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 5 years have passed since last update.

時間の計算 演算子 datetime timedelta

Last updated at Posted at 2020-02-26
import datetime

now = datetime.datetime.now()

d = datetime.timedelta(weeks=-1)
d2 = datetime.timedelta(weeks=1)
d3 = datetime.timedelta(days=365)

print(now)
print(now + d)
print(now - d2)
print(now - d3)
実行結果
2020-02-26 11:24:59.726696
2020-02-19 11:24:59.726696
2020-02-19 11:24:59.726696
2019-02-26 11:24:59.726696
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?