Language&Framework&Etc/Pandas
Datetime 다루기
머리올리자
2023. 2. 19. 23:38
날짜표현(STR -> DATETIME)
import datetime
format = '%Y-%m-%d %H:%M:%S'
datetime_str = '2018-05-13 12:34:56' # STRING
datetime_dt = datetime.datetime.strptime(datetime_str, format) # STRING -> DATETIME
print(type(datetime_dt))
print(datetime_dt)
<class 'datetime.datetime'>
2018-05-13 12:34:56
날짜표현(DATETIME -> STR)
datetime_str = datetime_dt.strftime('%Y-%m-%d %H:%M:%S')
print(type(datetime_str)) # <class 'str'>
print(datetime_str) # 2018-08-24 18:00:25
import datetime
format = '%Y-%m-%d %H:%M:%S'
datetime_str = '2018-05-13 12:34:56'
datetime_dt = datetime.datetime.strptime(datetime_str, format)
print(type(datetime_dt))
print(datetime_dt)