반응형
import datetime
현재 시간 출력하기
now = datetime.datetime.now()
#datetime.datetime(2025, 9, 25, 8, 59, 22, 622938)
시간 포맷 맞춰서 출력하기
now.strftime("%Y.%m.%d %H:%M:%S")
# 25.09.25 08:59:22
now.strftime("%Y.%m.%d %H:%M:%S")
# 2025.09.25 08:59:22
now.strftime("%D")
# 09/25/25
now.strftime("%y{}%m{}%d{} %H:%M:%S").format(*"년월일")
#25년09월25일 08:59:22
시간 더하기
datetime — Basic date and time types
Source code: Lib/datetime.py The datetime module supplies classes for manipulating dates and times. While date and time arithmetic is supported, the focus of the implementation is on efficient attr...
docs.python.org
now + datetime.timedelta(days=1)
# datetime.datetime(2025, 9, 26, 8, 59, 22, 622938)
특정 시간으로 바꾸기
now.replace(year=2050)
# datetime.datetime(2050, 9, 25, 8, 59, 22, 622938)
반응형
'AI > Python' 카테고리의 다른 글
[Python] ascii code <-> string 변환 방법 (0) | 2025.09.10 |
---|---|
[Python] 입력방법 input(), sys.stdin.readline(), strip() (0) | 2025.09.09 |
[Python] 모듈 만들기 (0) | 2025.09.05 |
[Python] NumPy list와 Python list 차이 (0) | 2025.09.04 |
[Python] 지수 표기 방법 + 2진수, 8진수, 16진수 변환 (0) | 2025.09.03 |