python 时间戳与日期

import time

 

""" 时间间隔是以秒为单位的浮点小数。1594696515.2807229 """

now = time.time()

 

""" 从返回浮点数的时间戳方式向时间元组转换 time.struct_time(tm_year=2020, tm_mon=7, tm_mday=14, tm_hour=11, tm_min=16, tm_sec=20, tm_wday=1, tm_yday=196, tm_isdst=0)"""

localtime = time.localtime(time.time())

 

""" 格式化日期 2020-07-14 11:18:20"""

localtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

 

""" 时间戳格式化 2020-03-02 00:00:00 """

localtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(1583078400))

 

""" 格式化转为时间戳 1583078400.0"""

localtime = time.mktime(time.strptime('2020-03-02', "%Y-%m-%d"))

你可能感兴趣的:(python,python)