nugawiki

./categories/back-end

Python datetime 날짜 연산·포맷

업데이트 2026-07-21 조회수

datetime

import datetime

d = datetime.datetime.now()
print(d)
print(d.year, d.month, d.day)
print(d.hour, d.minute, d.second)

wuhan_covid19 = datetime.datetime(2019, 12, 12)
wuhan_covid19 = datetime.datetime(2019, 12, 12, 3, 3, 3)

now = datetime.datetime.now()
print(now.strftime("%Y/%m(%B)/%d %A %p %I:%m:%S, 일년 중 %U 번째주, 일년 중 %j번째 날"))
print(now.strftime("%c"))
print(now.strftime("%x"))
print(now.strftime("%X"))

birthday = datetime.datetime(1988, 12, 11)
elapsed = now - birthday  # timedelta
print(elapsed)

Format Code

./comments