• 日期获取以及时间转化


    import time
    import datetime
    
    def getStamp():
        return time.time()
    
    def timeFormatStr(h,m,s):
        time=datetime.time(h,m,s)
    
    def today():
        return datetime.date.today()
    
    def strTime():
    
        # datetime.time(11,22,33).__format__("%H:M:%S")
        # :return:
    
       formats= time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
       return formats
    
    def stampToDatetime(stamp):
        return datetime.datetime.fromtimestamp(stamp)
    
    def addTime(h,m,s):
        fur=datetime.datetime.now()+datetime.timedelta(hours=h,minutes=m,seconds=s)
        return fur
    
    def makeStamp(strTime,dateTimestr,format):
        time.mktime(time.strptime(dateTimestr,format))
    
    def makeDate(y,m,d):
        return  datetime.date(y,m,d)
    
    def makeTime(h,m,s):
        return datetime.time(h,m,s)
    
    def getMicroSec():
        return datetime.datetime.now().microsecond
    print(getMicroSec())

    时间戳int(time.time()*10**6)

    微秒获取>>> datetime.datetime.now().microsecond
    475791

    start=

    >>> round(time.time()*10**3)

    1558451484349

      string:

    whitespace = ' \t\n\r\v\f'
    ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
    ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    ascii_letters = ascii_lowercase + ascii_uppercase
    digits = '0123456789'
    hexdigits = digits + 'abcdef' + 'ABCDEF'
    octdigits = '01234567'
    punctuation = r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
    printable = digits + ascii_letters + punctuation + whitespace

    string_rand=''.join(random.sample(string.hexdigits,random.randint(11,16)))

     

    # 日期转时间戳:

    import datetime,time
    a=time.strptime('2020-12-15 14:11:57',"%Y-%m-%d %H:%M:%S")
    b=time.mktime(a) # 取int
    print(b)
    # st=1607961600
    auit=None
    st=1608004500
    end=1608047999


    print(datetime.datetime.fromtimestamp(1607961600))
    2020-12-15 00:00:00
  • 相关阅读:
    react树节点异步加载和拖拽生成节点
    基于hook的ant design 的tab页的删除功能实现
    dva在hook里effect异步获取数据不同步问题
    SpringBoot整合Rredis
    SpringBoot实现Session共享
    SpringBoot整合Mybatis
    SpringBoot整合JPA多数据源
    SpringData关键字查询方法和自定义查询方法
    SpringBoot整合Mybatis多数据源
    jdbctemplate配置多数据源
  • 原文地址:https://www.cnblogs.com/SunshineKimi/p/10633578.html
Copyright © 2020-2023  润新知