Home >Backend Development >Python Tutorial >Python simple method to format time [strftime function]
The example in this article describes the simple method of formatting time in Python. It is shared with everyone for your reference. The details are as follows:
Walker often uses the current time and relative time to count the efficiency of program execution. Simple Remember it for easy copying.
>>> import time >>> startTime = time.time() >>> '%.2fs' % (time.time() - startTime) #相对时间 '24.51s' >>> '{:.2f}s'.format(time.time() - startTime) #相对时间 '37.55s' >>> time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) #格式化当前时间 '2016-01-05 10:34:06'
I hope this article will be helpful to everyone in Python programming.
For more Python simple methods to format time [strftime function], please pay attention to the PHP Chinese website for related articles!