首页 > 解决方案 > 以当前日期和时间格式保存文件

问题描述

我正在记录带有时间戳的传感器读数。

我想以当前日期和时间名称格式保存文件,例如 2019-08-20-15-20。

知道怎么做吗?

write_fmtt = " ".join("%4.8f" for _ in timestamped_camera_readings)
timestamped_camera_readings = np.append(float(timestamp),[arr1 , arr2 , arr3 , arr4])
write_fmtt += " %.0f"

with open("sensor reading.txt", "ab") as ff:
     np.savetxt(ff, np.expand_dims(timestamped_camera_readings, axis=0),fmt='%f')

标签: pythontimestampandroid-sensors

解决方案


你可以这样做:

with open("sensor reading {}.txt".format(datetime.now().strftime('%d-%m-%Y-%H-%M')), "ab") as ff:
    np.savetxt(ff, np.expand_dims(timestamped_camera_readings, axis=0),fmt='%f')

推荐阅读