프로그래밍/python
현재 날짜 가져오기 및 특정 일자 더하기
이휘재123
2022. 9. 28. 16:17
반응형
from datetime import timedelta
# 현재 날짜
today = datetime.today()
# 현재 년도, 월, 일, 시간
current_year = datetime.today().year
current_month = datetime.today().month
current_day = datetime.today().day
current_hour = datetime.today().hour
# 어제, 내일
yesterday = datetime.today() - timedelta(1)
tomorrow = datetime.today() + timedelta(1)
# 날짜 표기 형식 변경 -> YYYY.mm.dd HH:MM:SS
today = datetime.today().strftime(f'%Y.%m.%d %H:%M:%S')
반응형