Target environment
python 2.6.6 on CentOS 6.8
I used strftime () and strptime () in coding in the past, but I forget the contents because I have poor memory.
I found the following link.
http://docs.python.jp/2/library/datetime.html#strftime-strptime-behavior
Roughly speaking, d.strftime (fmt) works like time.strftime (fmt, d.timetuple ()) in the time module.
If you don't know the "x" that says "It works like x", you're done. Not a self-contained document.
Conversely, the datetime.strptime () class method creates a datetime object from a format string that corresponds to a date or time.
In my understanding (may be wrong)
--strftime (): Convert datetime type to specified format string --strptime (): Convert specified format string to datetime type
I implemented the code. Reference http://qiita.com/shibainurou/items/0b0f8b0233c45fc163cd
import datetime
today = datetime.datetime.today()
print today
wrk = today.strftime("%Y-%m-%d_%H:%M:%S")
print "strftime:", wrk
dt = datetime.datetime.strptime(wrk, "%Y-%m-%d_%H:%M:%S")
print "strptime:", dt
result
Success time: 0 memory: 9168 signal:0
2016-10-05 01:30:12.561105
strftime: 2016-10-05_01:30:12
strptime: 2016-10-05 01:30:12