본문 바로가기

Programming/Python

[Python] calendar, datetime 모듈 사용 예제

반응형
# 올해 중 오늘의 일수 구하는 예제

import calendar
from datetime import date

today = date.today().isoformat().split('-')
yeardays = 0

for i in range(int(today[1])):
	if i > 0:
		yeardays += calendar.monthrange(int(today[0]),i)[1]

yeardays += int(today[2])

print("Today is the", yeardays, "days of the year")
반응형