strftime 메소드

Nicholas·2022년 6월 5일
0

Django

목록 보기
12/14
  • django프로젝트를 진행하면서 CRUD기능이 있는 곳이라면 timestamp를 찍는경우가 많다.
    그리고 보통의 timestamp의 경우 시분초까지 찍는것이 당연하다.
  • 그런데 이렇게 찍은 시간을 일부만 활용하고싶을때 그때 사용하는 메소드가 strftime메소드이다.
  • 기본구조 : strftime(format code)
	#django review/views.py

	review.created_at.strftime('%Y''-''%m''-''%d')
  • format code 정리
    다음은 1989 C 표준이 요구하는 모든 포맷 코드 목록이며, 표준 C 구현이 있는 모든 플랫폼에서 작동합니다.
code의미
%a요일을 로케일의 축약된 이름으로.Sun, Mon, …, Sat(en_US)
So, Mo, …, Sa (de_DE)
%A요일을 로케일의 전체 이름으로.Sunday, Monday, …, Saturday (en_US)
Sonntag, Montag, …, Samstag (de_DE)
%w요일을 10진수로, 0은 일요일이고 6은 토요일입니다.0, 1, …, 6
%d월중 일(day of the month)을 0으로 채워진 10진수로.01, 02, …, 31
%b월을 로케일의 축약된 이름으로.Jan, Feb, …, Dec (en_US)
Jan, Feb, …, Dez (de_DE)
%B월을 로케일의 전체 이름으로.January, February, …, December (en_US)
Januar, Februar, …, Dezember (de_DE)
%m월을 0으로 채워진 10진수로.01, 02, …, 12
%y세기가 없는 해(year)를 0으로 채워진 10진수로.00, 01, …, 99
%Y세기가 있는 해(year)를 10진수로.0001, 0002, …, 2013, 2014, …, 9998, 9999
%H시(24시간제)를 0으로 채워진 십진수로.00, 01, …, 23
%I시(12시간제)를 0으로 채워진 십진수로.01, 02, …, 12
%p로케일의 오전이나 오후에 해당하는 것.AM, PM (en_US)
am, pm (de_DE)
%M분을 0으로 채워진 십진수로.00, 01, …, 59
%S초를 0으로 채워진 10진수로.00, 01, …, 59
%fMicrosecond as a decimal number, zero-padded to 6 digits.000000, 000001,…, 999999
%z±HHMM[SS[.ffffff]] 형태의 UTC 오프셋 (객체가 나이브하면 빈 문자열).(비어 있음), +0000, -0400, +1030, +063415, -030712.345216
%Z시간대 이름 (객체가 나이브하면 빈 문자열).(비어 있음), UTC, GMT
%j연중 일(day of the year)을 0으로 채워진 십진수로.001, 002, …, 366
%UWeek number of the year (Sunday as the first day of the week)
as a zero-padded decimal number.
All days in a new year preceding the first Sunday are
considered to be in week 0.
00, 01, …, 53
%WWeek number of the year (Monday as the first day of the week)
as a zero-padded decimal number.
All days in a new year preceding the first Monday are
considered to be in week 0.
00, 01, …, 53
%c로케일의 적절한 날짜와 시간 표현.Tue Aug 16 21:30:00 1988 (en_US)
Di 16 Aug 21:30:00 1988 (de_DE)
%x로케일의 적절한 날짜 표현.08/16/88 (None)
08/16/1988 (en_US)
16.08.1988 (de_DE)
%X로케일의 적절한 시간 표현.21:30:00 (en_US)
21:30:00 (de_DE)
%%리터럴 '%' 문자.%

참고 : https://docs.python.org/ko/3/library/datetime.html#strftime-strptime-behavior

profile
WEB Developer

1개의 댓글

comment-user-thumbnail
2022년 6월 5일

오!! 역시 한구님 정리왕!!!

답글 달기