jiemianNews/defs/format_time.py

20 lines
423 B
Python
Raw Permalink Normal View History

2022-08-02 13:14:10 +00:00
import pytz
from datetime import datetime, timedelta, timezone
tz = pytz.timezone("Asia/Shanghai")
date_format = "%Y/%m/%d %H:%M:%S"
def strf_time(data: int) -> str:
# data = 1648111686
ts = datetime.fromtimestamp(data, tz)
return ts.strftime(date_format)
def now_time() -> str:
# UTC
ts = datetime.now(timezone.utc)
# UTC+8
ts = ts + timedelta(hours=8)
return ts.strftime(date_format)