純記錄,詳情請參考
https://www.cnblogs.com/xiaoxiaoweng/p/10966220.html
1. 想要以時間來建文件夾
2. 解決辦法
time_str = datetime.datetime.now().strftime('%m%d-%H-%M')
tensorboard_path = "../output/{}/tensorboard/".format(time_str)
if not os.path.exists(tensorboard_path):
os.makedirs(tensorboard_path)
makedirs可以把中間的路徑不存在的文件夾也新建出來
(1)字符串轉datetime:
>>> string = '2014-01-08 11:59:58'
>>> time1 = datetime.datetime.strptime(string,'%Y-%m-%d %H:%M:%S')
>>> print time1
2014-01-08 11:59:58
(2)datetime轉字符串:
>>> time1_str = datetime.datetime.strftime(time1,'%Y-%m-%d %H:%M:%S')
>>> time1_str
'2014-01-08 11:59:58'