파이썬, date, time, timestamp 표현
from datetime import datetime
d = datetime.now() # 현재 날짜와 시간
print(d) # timestamp; 2022-01-17 13:43:18.336248
print(d.astimezone()) # timestamp+timezone; ...+09:00
print(d.date()) # date; 2022-01-17
print(d.time()) # time; 13:43:18.336248
print(d.year) # year; 2022
print(d.month) # month; 1
print(d.day) # day; 17
print(d.ctime()) # ctime; Mon Jan 17 13:43:18 2022
print(d.hour) # hour; 13
print(d.minute) # minute; 43
print(d.second) # second; 18
print(d.microsecond) # microsecond; 336248
print(d.strftime("%Y-%m-%d %H:%M:%S.%f")) # 2022-01-17 13:43:18.336248
print(d.strftime("%Y-%m-%d %H:%M:%S")) # 2022-01-17 13:43:18
print(d.strftime("%Y-%m-%d %H:%M")) # 2022-01-17 13:43
print(d.strftime("%Y-%m-%d")) # 2022-01-17
print(d.strftime("%y-%m-%d")) # 22-01-17
print(d.strftime("%H:%M:%S")) # 13:43:18
print(d.strftime("%y-%m-%d")) # 22-01-17
'Python 기초' 카테고리의 다른 글
파이썬, C 언어 printf() 함수 흉내내기 (0) | 2022.01.27 |
---|---|
파이썬, atexit 종료 처리기 (0) | 2022.01.24 |
사용 중인 파이썬 시스템 경로 목록을 출력하기 (0) | 2022.01.14 |
파이썬, 진수 변환표 출력하기 (2, 8, 10, 16진수 비교표) (0) | 2021.12.29 |
파이썬 포맷(형식) 문자열 다루기 (0) | 2021.11.19 |