0

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)

2 Answers 2

3

Use strftime

now.strftime("%Y-%m-%d %H-%M-%S")
Sign up to request clarification or add additional context in comments.

Comments

2

You can convert the timestamp to a string and then can use the replace() method to change the : to -

str(now).replace(":","-")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.