import time # 当前时间戳 current_time = time.time() print(current_time) # 1567498447.616138 # 当前时间结构化对象--当地时间 current_time_obj = time.localtime() print(current_time_obj) # time.struct_time(tm_year=2019,tm_mon=9,tm_mday=3,tm_hour=16,tm_min=16,tm_sec=2,tm_wday=1,tm_yday=246,tm_isdst=0) # 将结构化时间对象转化为时间戳 time_stamp = time.mktime(time.localtime()) print(time_stamp) # 1567498880.0 # 将结构化时间对象转化为字符串时间 time_str = time.strftime('%Y-%m-%d %X', time.localtime()) print(time_str) # 2019-09-03 16:29:29 # 将字符串时间转化为结构化时间对象 time_obj = time.strptime('2016-09-09 00:00:00', '%Y-%m-%d %X') print(time_obj) # time.struct_time(tm_year=2016,tm_mon=9,tm_mday=9,tm_hour=0,tm_min=0,tm_sec=0,tm_wday=4,tm_yday=253,tm_isdst=-1) # 推迟运行时间,参数3秒 time.sleep(3)