process_start_time = time.time() print('开始数据处理') # process function print('结束数据处理') process_stop_time = time.time() # 差的时间戳 diff_time = process_stop_time - process_start_time # 将计算出来的时间戳转换为结构化时间 struct_time = time.gmtime(diff_time) # 减去时间戳最开始的时间 并格式化输出 print('数据处理用了{0}年{1}月{2}日{3}小时{4}分钟{5}秒'.format( struct_time.tm_year - 1970, struct_time.tm_mon - 1, struct_time.tm_mday - 1, struct_time.tm_hour, struct_time.tm_min, struct_time.tm_sec ))
来源:https://www.cnblogs.com/gengyufei/p/12640594.html