索引 | 内容 | 属性 | 值 |
---|---|---|---|
0 | 年 | tm_year | 2015 |
1 | 月 | tm_mon | 1~12 |
2 | 日 | tm_mday | 1~31 |
3 | 时 | tm_hour | 0~23 |
4 | 分 | tm_min | 0~59 |
5 | 秒 | tm_sec | 0~61,60表示闰秒,61保留值 |
6 | 周几 | tm_wday | 0~6 |
7 | 第几天 | tm_yday | 1~366 |
8 | 夏令时 | tm_isdst | 0, 1, -1(表示夏令时) |
>>> import time
>>> time.timezone
-28800
>>> time.altzone
-32400
>>> time.daylight
0
>>> time.time()
1576070236.623945
>>> time.localtime()
time.struct_time(tm_year=2019, tm_mon=12, tm_mday=11, tm_hour=21, tm_min=17, tm_sec=29, tm_wday=2, tm_yday=345, tm_isdst=0)
>>> t = time.localtime()
>>> t.tm_hour
21
>>> t1 = time.localtime()
>>> t2 = time.asctime(t1)
>>> type(t2)
<class 'str'>
>>> t2
'Wed Dec 11 21:18:03 2019'
>>> t = time.ctime()
>>> type(t)
<class 'str'>
>>> t
'Wed Dec 11 21:19:02 2019'
>>> lt = time.localtime()
>>> ts = time.mktime(lt)
>>> type(ts)
<class 'float'>
>>> ts
1576070374.0
# run in ipython
t0 = time.clock()
time.sleep(3)
t1 = time.clock()
print(t1 - t0)
>>>
...
DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead
"""Entry point for launching an IPython kernel.
3.0017606999999984
...
This is separate from the ipykernel package so we can avoid doing imports until
符号 | 释义 |
---|---|
%Y | Year with century as a decimal number. |
%m | Month as a decimal number [01,12]. |
%d | Day of the month as a decimal number [01,31]. |
%H | Hour (24-hour clock) as a decimal number [00,23]. |
%M | Minute as a decimal number [00,59]. |
%S | Second as a decimal number [00,61]. |
%z | Time zone offset from UTC. 用 +HHMM 或 -HHMM 表示距离格林威治的时区偏移 H 代表十进制的小时数,M 代表十进制的分钟数 |
%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. |
%I | Hour (12-hour clock) as a decimal number [01,12]. |
%p | Locale‘s equivalent of either AM or PM. |
符号 | 释义 |
---|---|
%j | 一年中的第几天(001 - 366) |
%U | 一年中的星期数(00 - 53 星期天是一个星期的开始) 第一个星期天之前的所有天数都放在第 0 周 |
%w | 一个星期中的第几天(0 - 6,0 是星期天) |
%W | 和 %U 基本相同,不同的是 %W 以星期一为一个星期的开始 |
%x | 本地相应日期 |
%X | 本地相应时间 |
%y | 去掉世纪的年份(00 - 99) |
%Y | 完整的年份 |
%% | %号本身 |
>>> lt = time.localtime()
>>> ft = time.strftime("%Y-%m-%d %H:%M", lt)
>>> ft
'2019-12-11 21:20'
原文:https://www.cnblogs.com/yorkyu/p/12025286.html