본문 바로가기

Python 🎧

[python] datetime 모듈 - 오늘날짜/현재시간/날짜객체 생성

파이썬의 기본모듈인 datetime 모듈을 간단히 사용해보자

 

🌬️ 예제

import datetime as dt
now = dt.datetime.now() #오늘 날짜
year = now.year #년
month = now.month #월
day_of_week = now.weekday() #월:0, 화:1, 수:2, 목:3, 금:4, 토:5, 일:6
print(day_of_week)

#날짜 지정하여 객체 생성
today = dt.datetime(year=2024, month=10, day=16, hour=20)
print(today)

 

🌬️ 출력