zoukankan      html  css  js  c++  java
  • 日期获取以及时间转化

    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
  • 相关阅读:
    JavaScript、Jquery:获取各种屏幕的宽度和高度
    CSS:文字兩端加中線寫法
    CSS:公用
    JavaScript:基礎知識
    jQuery:播放/暂停 HTML5视频[轉]
    手機Web頁面信息
    jQuery:open和opener使用說明
    CSS:overflow使用說明
    jQuery:常用插件
    BootStrap:基礎知識
  • 原文地址:https://www.cnblogs.com/SunshineKimi/p/10633578.html
Copyright © 2011-2022 走看看