New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
01%20python/02.15%20%ED%8C%8C%EC%9D%B4%EC%8D%AC%EC%97%90%EC%84%9C%20%EB%82%A0%EC%A7%9C%EC%99%80%20%EC%8B%9C%EA%B0%84%20%EB%8B%A4%EB%A3%A8%EA%B8%B0 #74
Comments
class input_birthday(object):
|
today = datetime.datetime.now() next_birthday = birthday + relativedelta(year = today.year+1) print("다음 생일은 " + str(next_birthday.date()) + " 입니다") |
연습 문제 15.1bday = dt.datetime.strptime('2004.6.4','%Y.%m.%d')
bday.strftime("%Y년 %m월 %d일 {0}요일").format('월.화.수.목.금.토.일'.split('.')[x.weekday()])
연습 문제 15.2# param {datetime} bday
# returns {int} 실행 시각을 기준으로 한 만 나이
def calculateCurrentAge(bday):
today = dt.datetime.now()
y = today.year - bday.year
if today.month < bday.month + (1 if today.day < bday.day else 0):
return y - 1
return y
연습 문제 15.3# go away, clean code!
from datetime import datetime
# 다음 생일까지 남은 일수
def getRemainingDaysTillNextBDay(month, day):
today = datetime.now()
return (datetime.strptime(f'{today.year + (1 if today.month > month else 0)}.{month}.{day}','%Y.%m.%d') - today).days
# '내년' 생일까지 남은 일수
def getRemainingDaysTillNextBDayOnNextYear(month, day):
today = datetime.now()
return (datetime.strptime(f'{today.year + 1}.{month}.{day}','%Y.%m.%d') - today).days
# '내년' 생일까지 남은 분(minutes)
def getRemainingMinutesTillNextBDayOnNextYear(month, day):
today = datetime.now()
return round((datetime.strptime(f'{today.year + 1}.{month}.{day}','%Y.%m.%d') - today).total_seconds() / 60, 2)
연습 문제 15.4# 한 번에 하기
# relativedelta의 months 값을 사용하지 않아서 이걸 썼다고 해도 되는 건지는 모르겠지만, 일단 사용했습니다
import datetime as dt
from dateutil.relativedelta import relativedelta
def isLeapYear(year):
return (dt.datetime.strptime(f'{year}.2.1', '%Y.%m.%d') + relativedelta(days=28)).month == 2 |
|
연습문제2.15.1
연습문제2.15.2
연습문제2.15.3
연습문제2.15.4
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2.15 파이썬에서 날짜와 시간 다루기 — 데이터 사이언스 스쿨
https://datascienceschool.net/01%20python/02.15%20%ED%8C%8C%EC%9D%B4%EC%8D%AC%EC%97%90%EC%84%9C%20%EB%82%A0%EC%A7%9C%EC%99%80%20%EC%8B%9C%EA%B0%84%20%EB%8B%A4%EB%A3%A8%EA%B8%B0.html
The text was updated successfully, but these errors were encountered: