python - 以当前日期和时间格式保存文件
问题描述
我正在记录带有时间戳的传感器读数。
我想以当前日期和时间名称格式保存文件,例如 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')
解决方案
你可以这样做:
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')
推荐阅读
- java - 添加具有相同包名的外部类并破坏封装
- matrix - 通过旋转父矩阵将空间中的 3D 射线瞄准特定目标
- python-3.x - Pandas Dataframe to_csv 不会在 Mac 和 Linux 上附加(在 Windows 中会附加)
- python - Keras 模型的相同输出
- java - How to test method from repository which marked as @Modifying?
- java - 尝试将变量传递给 javafx/scenebuilder 中的另一个控制器时出错
- vue.js - 为什么将参数传递给映射的 getter 时我会得到未定义?
- thingsboard - 是否可以将 ThingsBoard 与虚拟 I2C 一起使用?
- docker - 如何为 docker-compose 指定特定于站点的卷
- angular - docker镜像中的角度构建错误