码迷,mamicode.com
首页 > 编程语言 > 详细

013python路--time模块

时间:2018-10-16 20:20:46      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:***   格式   time模块   str   mktime   print   localtime   bsp   注释文档   

import time
print(help(time.strftime))#注释文档

***time.sleep(0.1)

***print(time.time())#时间戳1539659532.6734543
print(time.mktime(time.localtime())#得到时间戳


print(time.clock())计算CPU执行时间

 

time-->str
time_format = ‘%Y%m%d %X‘ %H%M%S
***time_current = time.strftime(time_format)
print(time_current)
----------------------------------------------------------
***struct_time=time.localtime()
print(time.strftime(‘%Y-%m-%d %H-%M-%S‘,struct_time))
----------------------------------------------------------
***print(time.strftime(‘%Y-%m-%d %H-%M-%S‘))
====================================================================
str-->time
time.strptime(‘2016-09-08‘,‘%Y-%m-%d‘)
time.struct_time(tm_year=2016, tm_mon=9, tm_mday=8, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=252, tm_isdst=-1)
-------------------------------------------------------
a = time.strptime(‘2016-09-08‘,‘%Y-%m-%d‘)
print(a.tm_year)#得到年

 


a = time.gmtime() #结构化时间
print( a ) #UTC--世界标准时间
print(type(a))#<class ‘time.struct_time‘>
---------------------------------------------------------
**print(time.localtime()) #当地时间,对应gmtime

 


时间戳,格式时间,字符串时间,得到时间

 

 

import datetime
print(datetime.datetime.now())
#2018-10-16 12:02:13.488477
print(type(datetime.datetime.now()))
#<class ‘datetime.datetime‘>
str()--将class转化为str

 

013python路--time模块

标签:***   格式   time模块   str   mktime   print   localtime   bsp   注释文档   

原文地址:https://www.cnblogs.com/5014sy/p/9800326.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!