encoCi:Utimport datetimeimpert time
import datetime
import time
class TimeUtils:
@staticmethod
def get_nowt_imestamp():
return int(round(datetime.datetime.now().timestamp()1000))
@staticmethod
def get_hour_after_now_timestamp():
return int(round((datetime.datetime.now()+ datetime.timedelta(hours=1)).timestamp() 1000))
@staticmethod
def get_today_timestamp(hour=0):
t=str(datetime.date.today())+"%2d:00:00" %hour
timeArray =time.strptime(t,"%Y-%m-%d %H:%M:%S")
return int(time.mktime(timeArray))1000
@staticmethod
def get_today_end_timestamp():
t=str(datetime.date.today())+"23:59:59"
timeArray = time.strptime(t,"%Y-%m-%d %H:%M:%S")
return int(time.mktime(timeArray))1000
@staticmethod
def get_today_zero_seconds_end_timestamp():
t=str(datetime.date.today())+"23:59:00"
timeArray=time.strptime(t,"%Y-%m-%d %H:%M:%S")
return int(time.mktime(timeArray))1000
@staticmethod
def get_yesterday_timestamp(hour=0):
t=str(datetime.date.today()+ datetime.timedelta(days=-1))+"%02d:00:00" %hour
timeArray =time.strptime(t,"%Y-%m-%d %H:%M:%S")
return int(time.mktime(timeArray))1000
@staticmethod
def get_tomorrow_timestamp(hour=0):
t=str(datetime.date.today()+ datetime.timedelta(days=1))+" %02d:00:00" %hour
timeArray =time.strptime(t,"%Y-%m-%d %H:%M:%S")
return int(time.mktime(timeArray))*1000
@staticmethod
def get_tomorow_endtimestamp():
t = str(datetime.date.today() + datetime.timedelta(days=1)) + "23:59:59'"
timeArray =time.strptime(t,"%Y-%m-%d %H:%M:%S")
return int(time.mktime(timeArray)) * 1000
@staticmethod
def get_tomorrow_zero_seconds_end_timestamp():
t = str(datetime.date.today() + datetime.timedelta(days=1)) + "23:59:00"
timeArray = time.strptime(t, "%Y-%m-%d %H:%M:%S")
return int(time.mktime(timeArray)) * 1000
@staticmethod
def get_today_date():
today = time.localtime()
td = time.strftime("%Y%m%d", today)
return str(td)
@staticmethod
def get_tomorrow_date():
today = datetime.date.today()
tomorrow = today + datetime.timedelta(days=1)
td = time.strftime("名Y多md", time.strptime(str(tomorrow), "%Y-%m-%d"))
return str(td)
@staticmethod
def get_variable_timestamp(days=None, hours=None, minutes=None):
#入参处理
days = int (days) if isinstance(days,int) or isinstance(days,str) else 0
hours = int (hours)if isinstance(hours,int)or isinstance (hours, str)else 0
minutes = int(minutes)if isinstance (minutes, int)or isinstance(minutes, str)else 0
#获取时间
time_need = datetime.datetime.now()+ datetime.timedelta(days=days, hours=hours, minutes=minutes)
#转成毫秒级时间戳
return int(time_need.timestamp())*1000
if name=='main':
print(TimeUtils.get_variable_timestamp())