utils/timehelper.py包含以下函数:获取最小utc时间,datetime类型,适用于所有常见的mysql,无论是datime还是stamptime获取当前utc时间,datetime类型fromdatetimeimportdatetime,timedelta,timezonedefget_min_utc_timestamp()->datetime:return(datetime(year=1970,month=1,day=1)+timedelta(seconds=1)).replace(tzinfo=timezone.utc)defget_utc_now_timestamp()->datetime:"""https://blog.csdn.net/ball4022/article/details/101670024"""returndatetime.utcnow().replace(tzinfo=timezone.utc)deftimedelta_seconds(start_time:datetime,end_time:datetime=None)->int:"""返回两次之间的秒差"""如果不是end_time:end_time=get_utc_now_timestamp()returnint((end_time-start_time).total_seconds())defcustom_timestamp(base_timestamp:datetime,seconds:int,reduce=False):returnbase_timestamp+timedelta(seconds=seconds)\如果不减少\elsebase_timestamp-timedelta(seconds=seconds)deftimestamp_translate_gmt(timestamp:datetime)->str:返回timestamp.strftime('%a,%d%b%Y%H:%M:%SGMT')deftimestamp_translate_iso_8601(timestamp:datetime,include_millisecond:bool=False,include_timezone:bool=False)->str:ifinclude_timezone:ifnottimestamp.tzinfo:raiseValueError('时间戳参数不包含时区信息')returntimestamp.strftime("%Y-%m-%d%H:%M:%S.%f%z")ifinclude_millisecond:returntimestamp.strftime('%Y-%m-%d%H:%M:%S.%f')returntimestamp.strftime('%Y-%m-%d%H:%M:%S')
