728x90
반응형
str로 변환
timestamp -> str('2020-11-30 00:00:00')
import time
timestamp = time.time()
dt = str(datetime.fromtimestamp(timestamp))
print(dt)
# 2020-11-30 00:00:00
datetime -> str('2020-11-30 00:00:00')
from datetime import datetime
s = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(s)
# 2020-12-12 00:00:00
timestamp 로 변환
str('2020-11-30 00:00:00') -> timestamp
From date time import date time
import time
src='2020-11-30 00:00:00'
timestamp = time.mktime(datetime.strptime(src, '%Y-%m-%d %H:%M:%S').timetuple())
print(timestamp)
# 1606662000.0
str('2020-11-30 00:00:00') -> datetime
from datetime import datetime
src = '2020-11-30 00:00:00'
dt = datetime.strptime(src, '%Y-%m-%d %H:%M:%S')
print(dt)
# '2020-11-30 00:00:00'
timestamp -> datetime
from datetime import datetime
dt = datetime.fromtimestamp(1606662000)
print(dt)
# 2020-11-30 00:00:00
728x90
728x90
BIG
'Programming > Python' 카테고리의 다른 글
docker compose - python default 컨테이너 만들기 (0) | 2023.04.05 |
---|---|
try except를 깔끔하게 사용하기 - suppress (0) | 2023.01.31 |
NamedTuple 초기화 이후 수정하는 방법 (0) | 2020.12.11 |
Class, Object - 클래스, 객체 (0) | 2020.10.16 |
exception - 예외처리 (0) | 2020.10.13 |
댓글