首页 > 其他分享 >time

time

时间:2024-05-08 23:35:41浏览次数:18  
标签:-% int datetime time timeArray today

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())

标签:-%,int,datetime,time,timeArray,today
From: https://www.cnblogs.com/tao-1989/p/18181148

相关文章

  • debian12 timeshift无法正常运行,手动进行timeshift快照还原
    起因,/etc不小心被我删了注意,系统重要的话最好先用虚拟机练习一下一.挂载文件系统sudomount/dev/sdxn/mnt/dev/sdxn是你的块设备二.查看文件系统目录cd/mntls会出现@@hometimeshift-btrfs三.还原快照(1)先删除目标子卷sudorm-r@(2)再还原目标快照......
  • 【Azure Function】Azure Function中的Timer Trigger无法自动触发问题
    问题描述在AzureFunction中,部署了定时触发器函数(TimerTrigger),却无法按时触发。 问题解答登录Function的Kudu站点,查看logfiles中application/function/host目录下的日志文件,发现错误消息:Singletonlockrenewalfailedforblob'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx......
  • Windows下使用ONNXRuntime推理YOLOv8
    一、准备工作将训练好的pt文件转为onnx格式。yoloexportmodel=best.ptformat=onnxdevice=0opset=13dynamic#如果是动态Shape的话,命令行参数dydynamic一定要加上,不然就是static的模型二、下载与安装ONNXRuntime注意:下载安装onnxruntime-gpu时需要保证其与cuda的兼容......
  • sql server时间戳timestamp
    原文链接:https://www.cnblogs.com/hanke123/p/4741561.html在SQLServer中联机丛书是这样说的:SQLServertimestamp数据类型与时间和日期无关。SQLServertimestamp是二进制数字,它表明数据库中数据修改发生的相对顺序。实现timestamp数据类型最初是为了支持SQLServer恢......
  • time:Python的时间时钟处理
    前言time库运行访问多种类型的时钟,这些时钟用于不同的场景。本篇,将详细讲解time库的应用知识。获取各种时钟既然time库提供了多种类型的时钟。下面我们直接来获取这些时钟,对比其具体的用途。具体代码如下:importtimeprint(time.monotonic())print(time.monotonic_ns())pri......
  • datetime:Python日期与时间值管理计算
    前言datetime库也用于时间日期的处理,主要用于完成日期和时间的解析,格式化和算术运算。本篇,将完整的介绍datetime库的应用知识。datetime.date与time库一样,datetime库也有获取当前日期的类,日历日期值用datetime.date表示。比如datetime.date.today()。具体代码如下:importdate......
  • python教程6.3-time模块datetime模块
     time模块有下面几种表示形式:1、时间戳(timestamp),表示的是从1970年1⽉1⽇00:00:00开始按秒计算的偏移量。例⼦:1554864776.1619012、格式化的时间字符串,⽐如“2020-10-0317:54”3、元组(struct_time)共九个元素。由于Python的time模块实现主要调⽤C库,所以各个平台可能有所不......
  • Windows下使用ONNXRuntime的GPU进行推理时提示cudnn64_8.dll异常
    一、问题复现将模型放到GPU上推理时时发生的异常。OrtSessionOptionsAppendExecutionProvider_CUDA(session_options,0);...ort_outputs=session_.Run(Ort::RunOptions{nullptr},inputNames.data(),&input_tensor_,1,outNames.data(),outNames.size());二、解......
  • [转]ptp(precision time protocol)时钟同步
    一、介绍1:什么是ptpPTP(PrecisionTimeProtocol)是一个通过网络同步时钟的一个协议。当硬件支持时,PTP精度能达到亚微秒,比NTP(NetworkTimeProtocol)精度更高。2:ptp应用场景1)数据中心数据中心需要NTP/PTP同步,以确保集群的时域运行。同步对于虚拟机计算是必不可少的。日志事件的......
  • Do Loyal Users Enjoy Better Recommendations? Understanding Recommender Accuracy
    目录概实验设置实验Interaction-basedLoyaltyActiveTimePeriodbasedLoyaltyRecency代码JiY.,SunA.,ZhangJ.andLiC.DoLoyalUsersEnjoyBetterRecommendations?UnderstandingRecommenderAccuracyfromaTimePerspective.ICTIR,2022.概讨论了推荐中一......