zoukankan      html  css  js  c++  java
  • 模块之time与datetime

    模块之time与datetime

    import time
    print (time.clock())
    print(time.process_time()) #测量处理器运算时间
    print(time.altzone) #返回utc时间差,以秒计算
    print(time.asctime())#返回时间格式
    print(time.localtime())#返回本地时间的struct time 对象
    print(time.gmtime(time.time()))#返回utc时间的struc时间,与中国本地时间相差8小时,中国是东八区。
    print(time.asctime(time.localtime()))#返回时间格式
    print(time.ctime())#返回时间格式,与上条相同
    
    
    
    
    string_2_struct = time.strptime("2019/12/19","%Y/%m/%d")  #将日期字符品转换成struct时间格式
    print(string_2_struct)
    string_2_stamp= time.mktime(string_2_struct) #将struct时间对像转换成时间戳
    
    print(time.gmtime(time.time()))#将UTC时间戳转换成struct_time格式
    print(time.strftime("%Y-%m-%d %H:%M:%S",time.gmtime() )) #将UTC struct_time 格式转成指定的字符串格式########2019-12-19 14:53:37
    
    
    #时间的运算(时间加减)
    import  datetime
    print (datetime.datetime.now())  #返回当前时间
    print(datetime.date.fromtimestamp(time.time()))#将时间戳直接转成日期格式
    print (datetime.datetime.now()+datetime.timedelta(3))#当前时间加3天
    print(datetime.datetime.now()+datetime.timedelta(-3))#当前时间减3天
    print(datetime.datetime.now()+datetime.timedelta(hours=3))#当前时间加3小时
    print(datetime.datetime.now()+datetime.timedelta(minutes=30))#当前时间加30分钟
    
    
    c_time=datetime.datetime.now()
    print(c_time.replace(minute=3,hour=2))#把时间替换成2点3分钟。
    
    
    
    打印结果
    3e-07
    0.109375
    -32400
    Thu Dec 19 23:32:52 2019
    time.struct_time(tm_year=2019, tm_mon=12, tm_mday=19, tm_hour=23, tm_min=32, tm_sec=52, tm_wday=3, tm_yday=353, tm_isdst=0)
    time.struct_time(tm_year=2019, tm_mon=12, tm_mday=19, tm_hour=15, tm_min=32, tm_sec=52, tm_wday=3, tm_yday=353, tm_isdst=0)
    Thu Dec 19 23:32:52 2019
    Thu Dec 19 23:32:52 2019
    time.struct_time(tm_year=2019, tm_mon=12, tm_mday=19, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=353, tm_isdst=-1)
    time.struct_time(tm_year=2019, tm_mon=12, tm_mday=19, tm_hour=15, tm_min=32, tm_sec=52, tm_wday=3, tm_yday=353, tm_isdst=0)
    2019-12-19 15:32:52
    2019-12-19 23:32:52.735813
    2019-12-19
    2019-12-22 23:32:52.735813
    2019-12-16 23:32:52.735813
    2019-12-20 02:32:52.735813
    2019-12-20 00:02:52.735813
    2019-12-19 02:03:52.735813
  • 相关阅读:
    程序人生系列之新闻发布系统 1217
    $("expr","expr")
    jQuery 插件开发by:ioryioryzhan
    jQuery插件开发全解析 by gaojiewyh
    前端水好深
    网页设计师一定要知道的网站资源
    jQuery end()方法 by keneks
    前端书籍 by 小精灵
    emacs命令速查 摘
    jquery要怎么写才能速度最快? by 大白
  • 原文地址:https://www.cnblogs.com/kezi/p/12070907.html
Copyright © 2011-2022 走看看