Python에서 현재 날짜 출력하기
현재 날짜를 출력하려면, datetime
모듈에 date 메서드와
today 메서드를 순차적으로 적용해야 합니다.
현재 날짜를 출력해 봅시다:
res = datetime.date.today()
print(res) # 현재 날짜를 출력합니다
이제 현재 일(day), 월(month), 년(year)을 얻어봅시다:
print(res.day) # 일을 출력합니다
print(res.month) # 월을 출력합니다
print(res.year) # 년을 출력합니다
콘솔에 현재 일을 출력하세요.
콘솔에 현재 월을 출력하세요.
콘솔에 현재 년을 출력하세요.