日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

Python 时间常用函数及结构

發(fā)布時(shí)間:2024/8/23 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python 时间常用函数及结构 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
class time.struct_time 定義


The type of the time value sequence returned by gmtime(), localtime(), and strptime(). It is an object with a named tuple interface: values can be accessed by index and by attribute name. The following values are present:


Index ?| Attribute ? Values
---------------------------------------------------------------------
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]; see (2) in strftime() description
6 ? | tm_wday ? ?range [0, 6], Monday is 0
7 ? | tm_yday ? ?range [1, 366]
8 ? | tm_isdst ? ?0, 1 or -1; see below
N/A ? | tm_zone ? ?abbreviation of timezone name
N/A ? | tm_gmtoff ? offset east of UTC in seconds
---------------------------------------------------------------------


time.time()
Return the time in seconds since the epoch as a floating point number


time.gmtime([secs]) 0時(shí)區(qū)的時(shí)間
Convert a time expressed in seconds since the epoch to a struct_time in UTC in which the dst flag is always zero. If secs is not provided or None, the current time as returned by time() is used. Fractions of a second are ignored.?


time.localtime([secs]) 本地時(shí)間
Like gmtime() but converts to local time. If secs is not provided or None, the current time as returned by time() is used. The dst flag is set to 1 when DST applies to the given time.


time.mktime(t) ?與localtime()的功能恰好相反
This is the inverse function of localtime()


time.sleep(secs)
Suspend execution for the given number of seconds


time.strftime(format[, t])
Convert a tuple or struct_time representing a time as returned by gmtime() or localtime() to a string as specified by the format argument. If t is not provided, the current time as returned by localtime() is used. format must be a string. ValueError is raised if any field in t is outside of the allowed range.




Directive Meaning ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Notes
------------------------------------------------------------------------
%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. (1)
%S ? ? ? ? ?Second as a decimal number [00,61]. (2)
%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. (3)
%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. (3)
%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.ctime()
返回固定格式的本地時(shí)間

總結(jié)

以上是生活随笔為你收集整理的Python 时间常用函数及结构的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。