python—datetime time 模板学习

写在前面:本人在学习此内容是通过 https://www.cnblogs.com/pycode/p/date.html 文章学习!

时间模块——time

python 中时间表示方法有:时间戳_;格式化后的时间字符串;时间struct_time元组。
struct_time元组中元素主要包括tm_year(年)、tm_mon(月)、tm_mday(日)、tm_hour(时)、tm_min(分)、tm_sec(秒)、tm_wday(weekday0 - 6(0表示周日))、tm_yday(一年中的第几天1 - 366)、tm_isdst(是否是夏令时)

time.time():返回当前日期戳

 

 

time.ctime():返回(Sat Oct 20 14:30:29 2018)格式的时间字符(当地日期+时间和%c一样)

time.ctime(time.time()-86400):同时也可以转换时间戳

 

 

time.gmtime():将时间戳转换为struct_time格式

time.localtime():将当前系统时间戳转化为struct_time格式

 

 

time.mktime():struct_time格式的转为日期戳【这里回引用time.localtime()

 

 

time.strftime():struct_time格式的日期转为指定的“%*”形式输出

 

 

time.strptime():将自定义的时间格式(字符串)转为struct_time格式(可考虑嵌套input输入)

 

 

time.sleep():暂停时间:格式为:time.sleep(t)  {t为秒数(推迟执行的秒数)}

附表:函数总结:

time.time()

返回当前时间戳

time.ctime()

返回%c格式的时间

time.gmtime()

将时间戳转换为struct格式

time.localtime()

将系统时间转为struct格式

time.mktime()

将格式时间转为时间戳

time.sleep(t)

延迟执行下一条语句(t*秒)

time.strftime()

struct时间按格式输出

time.strptime()

将自定义时间格式转为struct格式

附表:time的时间格式表:

%a

显示简化的星期名称

%A

显示完整的星期名称

%w

星期的第几天(0代表周一)

%b

显示简化的月份名称

%B

显示完整的月份名称

%d

显示当月的第几天

%Y

完整的年份

%m

显示月份数

%j

显示当年的第几天

%y

去掉世纪计算的年份(00-99

%H

24小时制)显示小时

%l

12小时制)显示小时

%M

显示分钟数

%S

显示秒数

%U

显示当年的星期数

%c

本地日期+时间的表示

%x

本地对应的日期

%X

本地对应的时间

%p

本地am或者pm的相应符

%W

%U基本相同

%Z

时区的名字

附:转换关系

 

 

datetimedate(日期)time(时间)datetime(日期时间)等三种单独管理!

datetime.datetime 常用函数(datetime.date >>>通用>>> datetime.time):

datetimedatetime.today():返回当前默认的日期和时间(支持自定义时间)

 

>>>>自定义时间内容>>>>

 

datetime.datetime.now():返回当前时间

 

 

<datetime>.strftime():返回自定义格式化时间!

程序格式:[时间存储参数].strftime(“<时间控制符格式>”)

 

 

<datetime>.timetuple():将时间格式转为struct格式

程序格式:[时间存储参数].timetuple()

 

 

<datetime>.replace():返回一个修改过的datetime对象

 

 

datetime.datetime.strptime():将字符串转为日志格式(time的格式)对象

 

 

 

datetime.timedelta 时间运算:

可用参数:

days()  seconds()  microseconds(微秒)  milliseconds(毫秒)  minutes(分钟)  hours(小时)  weeks(/7t)

 

新人初学!笔记糙乱不要见怪!

posted @ 2018-10-20 20:05  Mirror王宇阳  阅读(416)  评论(0编辑  收藏  举报