-
[Python]문자열로된 날짜 datetime으로 변환python 2021. 3. 26. 14:43728x90반응형
"2016-01-01" 이라는 문자열을 아래와 같이 사용하면 datetime 객체로 변환 가능
import date
test_date="2016-01-01"
convert_date = datetime.datetime.strptime(test_date, "%Y-%m-%d").date()
"20160101"이라는 문자열을 아래와 같이 사용하면 역시 변환 가능
import date
test_date="20140206"
convert_date = datetime.datetime.strptime(test_date, "%Y%m%d").date()
결과 값은 전부 "2016-01-01"의 datetime 객체 형태로 반환된다.
아래와 같이 strftime을 사용하여 현재일의 년월일을 문자열로 구할 수 있다.
today = datetime.datetime.today().strftime("%Y-%m-%d").split('-')
@ 해당 블로그에 파이썬 정보 많으니 참조
brownbears.tistory.com/18?category=168282
[Python]문자열로된 날짜 datetime으로 변환
"2016-01-01" 이라는 문자열을 아래와 같이 사용하면 datetime 객체로 변환 가능 1 2 3 4 import date test_date="2016-01-01" convert_date = datetime.datetime.strptime(test_date, "%Y-%m-%d").date() cs..
brownbears.tistory.com
728x90반응형'python' 카테고리의 다른 글
Numpy 란 ? (0) 2021.04.01 Python入門 (0) 2021.03.31 Interactive Learning Sites for Python (0) 2021.03.25 금융데이터이해와 분석 with python (0) 2021.03.25 Python 기초 (0) 2021.03.24