zoukankan      html  css  js  c++  java
  • Python 学习笔记 -- time模块内置函数及实例

     1 import time
     2 #时间戳:1970.1.1.08:00:00起到现在的总秒数
     3 #-----------------------------Time模块内置函数-----------------------------
     4 #time.altzone #返回格林威治西部的夏令时地区的偏移秒数
     5 print("夏令时区的偏移秒数:time.altzone %d " % time.altzone)
     6 
     7 print("
    -----------------分割线-----------------
    ")
     8 
     9 #time.localtime() 返回当地时间的时间元组,如果传入时间戳,则返回对应时间戳的时间元组
    10 print("time.localtime():",time.localtime())
    11 print("time.lcoaltime(1.0):",time.localtime(1.0))
    12 
    13 print("
    -----------------分割线-----------------
    ")
    14 
    15 #time.asctime 接受时间元组([tupletime]) 返回“Tue Dec 11 18:07:14 2008”(2008年12月11日 周二18时07分14秒)
    16 print("time.asctime(time.localtime()):%s"%time.asctime(time.localtime()))
    17 
    18 print("
    -----------------分割线-----------------
    ")
    19 
    20 #time.clock() 用哟浮点数计算的秒数返回当前的CPU时间。
    21 print("time.clock() %s" % time.clock())
    22 
    23 print("
    -----------------分割线-----------------
    ")
    24 
    25 #time.ctime([secs]) 作用相当于asctime(localtime(secs)),未给参数是相当于asctime()
    26 print("time.ctime():",time.ctime())
    27 
    28 print("
    -----------------分割线-----------------
    ")
    29 
    30 #time.gmtime([secs]) 接受时间戳(1970纪元经过的浮点秒数),返回格林威治天文时间下的时间元组
    31 print("time.gmtime([secs])",time.gmtime())
    32 
    33 print("
    -----------------分割线-----------------
    ")
    34 
    35 #time.mktime(t) 接受时间元组返回时间戳
    36 print("time.mktime(time.localtime()):",time.mktime(time.localtime()))
    37 
    38 print("
    -----------------分割线-----------------
    ")
    39 
    40 #time.sleep(secs) 推迟调用线程运行,secs指秒数
    41 time.sleep(10)
    42 
    43 print("
    -----------------分割线-----------------
    ")
    44 
    45 #time.strftime(fmt[,tupletime]) 接受时间元组,返回字符串,格式由fmt决定
    46 print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))
    47 
    48 print("
    -----------------分割线-----------------
    ")
    49 
    50 #time.time() 返回当前时间戳(1970纪元后经过的浮点秒数)
    51 print("time.time():",time.time())
  • 相关阅读:
    默哀STAND SILENTLY!
    用虚拟机优化Windows(update:2008.4.24)
    UE的心情指数?
    God of War III 的发售日期?
    2009/8/15应该是一个愉快的夜晚.为林肯公园中国10月演唱会做好准备
    北京2008奥运会完美谢幕!
    《The Pursuit of Happyness / 当幸福来敲门》(2006)
    2007林肯公园上海演唱会观后感(实况像片/MP3) update:2008.1.31
    2008早上好
    Active Object C++智能指针实现
  • 原文地址:https://www.cnblogs.com/jiangchenxi/p/8087545.html
Copyright © 2011-2022 走看看