time模块

time模块:

1 import time
2 help(time)
 1 time()
 2 sleep()
 3 gmtime()
 4 localtime()
 5 asctime()
 6 ctime()
 7 mktime()
 8 strftime()
 9 strptime()
10 tzset()
 1 time.time()
 2 #返回1970年距离现在相差的秒数
 3 time.sleep(2)
 4 #推迟两秒
 5 time.gmtime()/time.gmtime(n)
 6 #utc时间元组/时间戳的utc时间元祖
 7 time.localtime()/time.localtime(n)
 8 #本地时间元组/时间戳的本地时间元祖
 9 time.asctime()
10 #时间元组转换为字符串
11 time.ctime()
12 #时间戳转换为字符串
13 time.strftime()
14 #把时间元组转换为指定格式的字符串
15 time.strptime()
16 #把字符串转换为时间元组
函数对比
1 time.time()
2     ||时间戳转换为字符串
3 time.ctime()
4     ||字符串转换为时间元组
5 time.strptime()
6     ||时间元组转换为字符串
7 time.strftime()
1 time.time()
2     ||时间戳转换为时间元组
3 time.localtime()
4     ||时间元组转换为字符串
5 time.asctime()
1 实例:
2 t=time.time()
3 tu_t=time.localtime(t)
4 str_t=time.strftime('%Y-%m-%d %H:%M:%S',tu_t)
5 re_tu=time.strptime(str_t,'%Y-%m-%d %H:%M:%S')
6 re_t=time.mktime(re_tu)
7 print('时间戳:%s\n时间元组:%s\n字符串:%s\n时间元组:%s\n'时间戳:%s' %(t,tu_t,str_t,re_tu,re_t))

 

 

posted @ 2019-04-11 10:22  竹心_兰君  阅读(132)  评论(0编辑  收藏  举报