udpate
This commit is contained in:
parent
db1e2710bf
commit
72ed31076f
@ -1,6 +1,8 @@
|
|||||||
# 使用Python 3.10作为基础镜像
|
# 使用Python 3.10作为基础镜像
|
||||||
FROM python:3.10-slim
|
FROM python:3.10-slim
|
||||||
|
|
||||||
|
# 设置时区
|
||||||
|
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
|
||||||
# 清空所有默认源
|
# 清空所有默认源
|
||||||
RUN rm -rf /etc/apt/sources.list.d/* && \
|
RUN rm -rf /etc/apt/sources.list.d/* && \
|
||||||
rm -f /etc/apt/sources.list
|
rm -f /etc/apt/sources.list
|
||||||
|
|||||||
@ -6,10 +6,12 @@ from typing import TypeVar, Generic
|
|||||||
from fastapi import status
|
from fastapi import status
|
||||||
import json
|
import json
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
from app.core.utils import CommonUtils
|
||||||
|
|
||||||
class CustomJSONEncoder(json.JSONEncoder):
|
class CustomJSONEncoder(json.JSONEncoder):
|
||||||
def default(self, obj):
|
def default(self, obj):
|
||||||
if isinstance(obj, datetime):
|
if isinstance(obj, datetime):
|
||||||
return obj.strftime('%Y-%m-%d %H:%M:%S')
|
return CommonUtils.get_asia_datetime(obj)
|
||||||
if isinstance(obj, time):
|
if isinstance(obj, time):
|
||||||
return obj.strftime('%H:%M:%S')
|
return obj.strftime('%H:%M:%S')
|
||||||
elif isinstance(obj, date):
|
elif isinstance(obj, date):
|
||||||
|
|||||||
@ -7,7 +7,15 @@ class CommonUtils:
|
|||||||
"""工具类"""
|
"""工具类"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_current_time(timezone='Asia/Shanghai'):
|
def get_asia_datetime(my_datetime: datetime, timezone='Asia/Shanghai') -> str:
|
||||||
|
"""
|
||||||
|
将时间转换为UTF-8编码
|
||||||
|
"""
|
||||||
|
tz = pytz.timezone(timezone)
|
||||||
|
return my_datetime.astimezone(tz).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_current_time(timezone='Asia/Shanghai') -> str:
|
||||||
"""
|
"""
|
||||||
获取指定时区的当前时间
|
获取指定时区的当前时间
|
||||||
:param timezone: 时区名称,默认为上海时区(东八区)
|
:param timezone: 时区名称,默认为上海时区(东八区)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user