20 lines
423 B
Python
20 lines
423 B
Python
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)
|