티스토리 뷰
728x90
import datetime
DAY_OF_WEEK = {
"MONDAY": 0,
"TUESDAY": 1,
"WEDNESDAY": 2,
"THURSDAY": 2,
"FRIDAY": 2,
"SATURDAY": 2,
"SUNDAY": 6
}
def string_to_date(dt, format='%Y%m%d'):
return datetime.datetime.strptime(dt, format)
def date_to_string(date, format='%Y%m%d'):
return datetime.datetime.strftime(date, format)
def day_of_week(dt):
return string_to_date(dt).weekday()
dt = '20210101'
if day_of_week(dt) == DAY_OF_WEEK['SUNDAY']:
None
How do I get the day of week given a date?
I want to find out the following: given a date (datetime object), what is the corresponding day of the week? For instance, Sunday is the first day, Monday: second day.. and so on And then if the ...
stackoverflow.com
[python] 날짜, 시간관련 모듈
파이썬에서 날짜와 시간을 다루는 방법을 알아보자. 지금 현재의 날짜와 시간을 문자열로 출력하려면 strftime 메서드를 이용하면 된다. 날찌, 시간형식의 문자열을 datetime으로 만들려면 strptime을
godoftyping.wordpress.com
728x90
'공부' 카테고리의 다른 글
[Sh] command $? exit() & timer <= 30s failed (0) | 2021.01.21 |
---|---|
[Sh] exit() (0) | 2021.01.21 |
[Python] weekday(); week of day (feat. date_to_string & string_to_date) (0) | 2021.01.21 |
[Python] String to Date; Date to String (0) | 2021.01.19 |
[Slack] slacker.Error: missing_scope (0) | 2021.01.14 |
[Chart.js] make chart image (0) | 2021.01.14 |
댓글
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- 142,048
- Today
- 28
- Yesterday
- 221
TAG
- follower
- 메디파크 내과 전문의 의학박사 김영수
- Kluge
- 인스타그램
- 어떻게 능력을 보여줄 것인가?
- 팔로워 수 세기
- Bot
- 책그림
- 클루지
- 개리마커스
- COUNT
- 김달
- wlw
- 유투브
- 연애학개론