Notice
Recent Posts
Recent Comments
Link
반응형
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- javascript #자바스크립트 #공백제거함수
- oracle #
- JSP #Java #JQuery
- react #props #state
- flutter #flutter개념 #특징 #장단점
- kotlin #코틀린 #SpringDataJPA단점
- 인텔리제이 #intelliJ #패키지생성 #package
- react #ref
- yarn #오류
- decode함수
- JPA #Springboot #java
- git #삭제
- Django #장고 #에러해결방법 #templatetags
- MariaDB #Error
- PostgreSQL
- SQL
- python #json
- springboot #에러
- db #mysql #mariadb
- blockscope
- react #event
- regexp_substr함수
- 데이터집계
- react #리액트 #JSX
- db #with절 #오라클 #oracle #쿼리 #query
- react #mini_project #study
- django #db #오류
- 인프런 #assertThat #오류
- DTO #VO
- Django #Static
Archives
- Today
- Total
감자의 개발공부 일지
[Python]strftime과 strptime의 차이점 본문
반응형
날짜 유효성 검사 관련 학습을 하다가 strftime과 strptime가 헷갈려서 포스팅으로 기록을 하기로 했다.
<strftime과 strptime의 차이점>
1. 문자열 -> 날짜(시간포함)로 변환 : strptime
예제
from datetime import datetime
datetime_string = "2020-09-30"
print("datetime_string=", datetime_string)
print("type of datetime_string=", type(datetime_string))
datetime_datetime = datetime.strptime(datetime_string, "%Y-%m-%d")
print("datetime_datetime=", datetime_datetime)
print("type of datetime_datetime=",type(datetime_datetime))
결과
datetime_string= 2020-09-30
type of datetime_string= <class 'str'>
datetime_datetime= 2020-09-30 00:00:00
type of datetime_datetime= <class 'datetime.datetime'>
2. 날짜(시간포함) -> 문자열로 변환 : strftime
예제
from datetime import datetime
current = datetime.now()
current_date = current.strftime("%Y-%m-%d")
print("current_date : ", current_date)
결과
current_date : 2020-09-30
반응형
'Python' 카테고리의 다른 글
[Python] 배열과 리스트의 차이점 (0) | 2022.10.04 |
---|---|
[Python-pandas] loc와 iloc의 차이점 (0) | 2022.10.04 |
[Python] 날짜 유효성 검사하기 (1) | 2022.09.30 |
[Python] 각 값의 datatype 확인하기 (0) | 2022.09.29 |
[Python] 주석 단축키가 안될때 (0) | 2022.09.28 |