python3_time()
1、打印时间戳
格式:2022-03-05 17:04:38.945
import time def get_time_stamp(): ct = time.time() print(ct) ## time.time()返回当前时间的时间戳 local_time = time.localtime(ct) print(local_time) ## time.localtime(sece)返回本地时间,如果未提供参数secs或None,则使用time.time()返回的当前时间 time.sleep(60) data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time) data_head1 = time.strftime("%Y-%m-%d %H:%M:%S") print(data_head) print(data_head1) ## time.strftime(format[, t])返回格式化后的时间,如果未提供参数t,则使用time.localtime()返回的当前时间 data_secs = (ct - int(ct)) * 1000 print(data_secs) time_stamp = "%s.%03d" % (data_head, data_secs) print(time_stamp) get_time_stamp() ''' 1646471078.9451933 time.struct_time(tm_year=2022, tm_mon=3, tm_mday=5, tm_hour=17, tm_min=4, tm_sec=38, tm_wday=5, tm_yday=64, tm_isdst=0) 2022-03-05 17:04:38 2022-03-05 17:05:38 945.1932907104492 2022-03-05 17:04:38.945 '''

浙公网安备 33010602011771号