English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
This article describes a simple method of formatting time in Python and shares it with everyone for reference, as follows:
walker often uses current time and relative time to calculate the efficiency of program execution, simply noting it for easy copying.
>>> import time >>> startTime = time.time() >>> '%.2fs' % (time.time() - startTime) # Relative time '24.51s' >>> '{:.2f}s'.format(time.time() - startTime) # Relative time '37.55s' >>> time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) # Format the current time '2016-01-05 10:34:06'
PS: This site also provides a Unix timestamp conversion tool (summary of timestamp operations in various commonly used languages), which is very practical and provides a reference for everyone:
Unix Timestamp (timestamp) Conversion Tool:
http://tools.jb51.net/code/unixtime
Readers who are interested in more Python-related content can check the special topics on this site: 'Summary of Python Date and Time Operation Skills', 'Summary of Python URL Operation Skills', 'Summary of Python Image Operation Skills', 'Python Data Structures and Algorithms Tutorial', 'Summary of Python Socket Programming Skills', 'Summary of Python Function Usage Skills', 'Summary of Python String Operation Skills', 'Classic Tutorial of Python入门与进阶', 'Summary of Python File and Directory Operation Skills', and 'Summary of Python File and Directory Operation Skills'.
I hope the content described in this article will be helpful to everyone's Python program design.
Declaration: The content of this article is from the Internet, the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (When reporting, please replace # with @ and provide relevant evidence. Once verified, this site will immediately delete the suspected infringing content.)