2022-08-08 06:38:00 +00:00
|
|
|
from datetime import datetime, timedelta, timezone
|
2022-03-19 17:44:35 +00:00
|
|
|
date_format = "%Y-%m-%dT%H:%M:%SZ"
|
|
|
|
|
|
|
|
|
|
|
|
def strf_time(data: str) -> str:
|
|
|
|
# data = "2021-07-17T09:14:05Z"
|
2022-04-29 15:54:07 +00:00
|
|
|
if data:
|
|
|
|
ts = datetime.strptime(data, date_format)
|
|
|
|
else:
|
|
|
|
return "未知"
|
2022-03-19 17:44:35 +00:00
|
|
|
# UTC+8
|
|
|
|
ts = ts + timedelta(hours=8)
|
|
|
|
return ts.strftime("%Y/%m/%d %H:%M:%S")
|
|
|
|
|
|
|
|
|
|
|
|
def now_time() -> str:
|
|
|
|
# UTC
|
2022-08-08 06:38:00 +00:00
|
|
|
ts = datetime.now(timezone.utc)
|
2022-03-19 17:44:35 +00:00
|
|
|
# UTC+8
|
|
|
|
ts = ts + timedelta(hours=8)
|
|
|
|
return ts.strftime("%Y/%m/%d %H:%M:%S")
|