如何将当前日期时间传递给python中的字符串? [英] How can pass the current datetime to string in python?

查看:63
本文介绍了如何将当前日期时间传递给python中的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将活动的当前日期和时间传递给字符串值,以便每当我在程序中保存图片或任何内容时,都可以使用其自己的特定名称+ 当前时间进行保存.在一起,但是我可能由于:而遇到错误!以下格式可以满足我的期望:

I'm trying to pass the current date and time of activities to string value so that whenever I saved my picture or anything during the program it can be saved by its own certain name + current time together but I faced error probably due to : ! Following format would fulfill my expectation :

2019-05-22 21-33-34 instead of 2019-05-22 21:33:34.433134 

import datetime as dt
import matplotlib.pyplot as plt

dtime = dt.time()
now=dt.datetime.now()
now.isoformat()
print(now)

...

plt.savefig(f'{now}.png')

...

test_RNN.to_csv(f'test_RNN_history{now}.csv', sep=',', header=None, index=None)

推荐答案

使用

这篇关于如何将当前日期时间传递给python中的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆