zoukankan      html  css  js  c++  java
  • Python学习_time模块使用

    #!/usr/bin/python

    #-*- encoding=UTF-8 -*-

    #DATE:2018-05-12

    
    
    """
    %y  两位数的年份00-99
    %Y 四位数的年份000-9999
    %m 月份01-12
    %d   日01-31
    %H  小时(24小时制即0~23点)
    %I    小时(12小时制01~12)
    %M  分钟
    %S   秒
    """
    print('====小结====')
    print('一、time模块')
    time.time() #获取当前时间的时间戳
    time.gmtime()#获取国际即UTC的格式化时间(tm_year=2018,tm_mon=5 ……),也可以将时间戳变为struc_time时间
    time.localtime()#获取本地时间的格式化时间(struct_time)
    # 注:
    # 格式化时间便于我们知道当前时间是本周或本年的第几天
    # 时间戳一般用于计算时间差
    time.strftime(format='',p_tuple='')#将struc_time格式化为自定义格式的时间
    #print(time.strftime('%Y-%m-%d %H%M%S',time.localtime()))
    # #2018-05-12 092320
    time.strptime(string='',format='')#将特定时间,格式化为格式化时间struc_time
    #print(time.strptime('2018/05/10','%Y/%m/%d'))
    # #time.struct_time(tm_year=2018, tm_mon=5, tm_mday=10, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=130, tm_isdst=-1)
    time.clock()#获取CPU运行程序工作的时间,但sleep不算,当时CPU是不工作的
    time.asctime(p_tuple='')#将struk_time 格式化为字符串时间如:'Sat Jun 06 16:26:11 1998'.
    time.ctime(seconds=None)#将秒数即时间戳格式化为字符串时间:'300'-->Thu Jan  1 08:05:00 1970
    time.mktime(p_tuple='')#将struc_time时间即gmtime(),localtime()格式化为时间戳
    time.sleep(seconds='')#暂停多少秒

     

    示例题:算时间差

     

    Python函数时间元组(struct_time)的含义和用法

    Python函数用一个元组装起来的9组数字处理时间:
    包含的元素见下表:

    时间元组各个元素的含义如下:

     

  • 相关阅读:
    【bzoj1010】[HNOI2008]玩具装箱toy
    bzoj 3173
    bzoj 1179
    bzoj 2427
    bzoj 1051
    bzoj 1877
    bzoj 1066
    bzoj 2127
    bzoj 1412
    bzoj 3438
  • 原文地址:https://www.cnblogs.com/sunxiuwen/p/9027826.html
Copyright © 2011-2022 走看看