zoukankan      html  css  js  c++  java
  • 内置标准库之time

    标准库都比较基础,就简单的把官方手册的内容选取一些copy过来,以备日后翻阅。

    首先Python是从1970年开始记录时间,也就是Unix诞生那年。UTC也就是所谓的世界标准时间,DST代表夏时令。

    • The epoch is the point where the time starts. On January 1st of that year, at 0 hours, the “time since the epoch” is zero. For Unix, the epoch is 1970. 

    time模块内置变量:

    •     timezone -- difference in seconds between UTC and local standard time
    •     altzone -- difference in  seconds between UTC and local DST time
    •     daylight -- whether local time should reflect DST
    •     tzname -- tuple of (standard time zone name, DST time zone name)

    time模块内置方法:      

    •   time() -- return current time in seconds since the Epoch as a float
      • 参数:无
    •     clock() -- return CPU time since process start as a float
      • 参数:无
    •     sleep() -- delay for a number of seconds given as a float
      • 参数:sleep(seconds)
    •     gmtime() -- convert seconds since Epoch to UTC tuple
      • 参数:gmtime(seconds)
    •     localtime() -- convert seconds since Epoch to local time tuple
      • 参数:localtime(seconds)
    •     asctime() -- convert time tuple to string
      • 参数:asctime(tuple)
    •     ctime() -- convert time in seconds to string
      • 参数:ctime(seconds)
    •     mktime() -- convert local time tuple to seconds since Epoch
      • 参数:mktime(tuple)
    •     strftime() -- convert time tuple to string according to format specification
      • 参数:strftime(format[,tuple]) ==strftime(“格式”,tuple)
    •     strptime() -- parse string to time tuple according to format specification
      • 参数:strptime(string[,format]) ==strptime("字符串","格式")
    •     tzset() -- change the local timezone
      • 参数:无

    其中struct_time格式化格式为:元组(tm_year, tm_mon, tm_mday, tm_hour, tm_min,tm_sec, tm_wday, tm_yday, tm_isdst)

    IndexAttributeValues
    0 tm_year (for example, 1993)
    1 tm_mon range [1, 12]
    2 tm_mday range [1, 31]
    3 tm_hour range [0, 23]
    4 tm_min range [0, 59]
    5 tm_sec range [0, 61]
    6 tm_wday range [0, 6], Monday is 0
    7 tm_yday range [1, 366]
    8 tm_isdst 0, 1 or -1

    其中格式化字符串时用到的格式:

    The following directives can be embedded in the format string. They are shown without the optional field width and precision specification, and are replaced by the indicated characters in the strftime() result:

    DirectiveMeaningNotes
    %a Locale’s abbreviated weekday name.  
    %A Locale’s full weekday name.  
    %b Locale’s abbreviated month name.  
    %B Locale’s full month name.  
    %c Locale’s appropriate date and time representation.  
    %d Day of the month as a decimal number [01,31].  
    %H Hour (24-hour clock) as a decimal number [00,23].  
    %I Hour (12-hour clock) as a decimal number [01,12].  
    %j Day of the year as a decimal number [001,366].  
    %m Month as a decimal number [01,12].  
    %M Minute as a decimal number [00,59].  
    %p Locale’s equivalent of either AM or PM.  
    %S Second as a decimal number [00,61].  
    %U Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0.  
    %w Weekday as a decimal number [0(Sunday),6].  
    %W Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0.  
    %x Locale’s appropriate date representation.  
    %X Locale’s appropriate time representation.  
    %y Year without century as a decimal number [00,99].  
    %Y Year with century as a decimal number.  
    %z Time zone offset indicating a positive or negative time difference from UTC/GMT of the form +HHMM or -HHMM, where H represents decimal hour digits and M represents decimal minute digits [-23:59, +23:59].  
    %Z Time zone name (no characters if no time zone exists).  
    %% A literal '%' character.

    最后一张图,,结束内置time模块。

  • 相关阅读:
    字符串的字典排序
    最长上升子序列LIS(Longest Increasing Subsequence)
    小猴子下落
    二叉树的遍历
    7,Uipath实践-从零开始写demo-UiPath Foreach循环
    6,UiPath实践-从零开始写demo-if判断
    5,Uipath实践-从零开始写demo-调试Get Mail
    3,UiPath实践-从零开始写demo-读取Email
    4,Uipath实践-从零开始写demo-Uipath调试
    2,UiPath探索-Hello World
  • 原文地址:https://www.cnblogs.com/lucas0625/p/7661751.html
Copyright © 2011-2022 走看看