Home > Backend Development > Python Tutorial > Python simple method to format time [strftime function]

Python simple method to format time [strftime function]

高洛峰
Release: 2017-01-12 15:26:04
Original
1719 people have browsed it

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'
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template