一、time与datetime
常用三种方式表示时间:
1、时间戳timestamp: 返回float类型
>>> #timestamp时间戳
>>>print(time.time())
>>>type(time.time())
>1543232724.692848
>float
>>>#格式化的时间字符串
>>>print(time.strftime("%Y-%M-%D %X"))
>2018-49-11/26/18 19:49:16
>>>print(time.strftime("%y-%m-%d %X"))
>18-11-26 19:49:54
>>>print(time.strftime("%Y-%m-%d"))
>2018-11-26
>>>print(time.localtime()) #本地时区的struct_time
>time.struct_time(tm_year=2018, tm_mon=11, tm_mday=26, tm_hour=19, tm_min=55, tm_sec=24, tm_wday=0, tm_yday=330, tm_isdst=0)
>>>print(time.gmtime()) #UTC时区的struct_time
>time.struct_time(tm_year=2018, tm_mon=11, tm_mday=26, tm_hour=11, tm_min=55, tm_sec=25, tm_wday=0, tm_yday=330, tm_isdst=0)
格式化format时间–>结构化struct时间
.striptime()
结构化struct时间–>格式化format时间