iNTERFACEWARE Products Manual > Learning Center > Learning Python > Working With Strings > String Functions > Getting Time Information |
|
Looking for Iguana v.5 or v.6? Learn More or see the Help Center.
Python provides a convenient way to obtain the current date and time in whatever format your application needs. To do this, use the strftime() function, which is included as part of the time module. Here is an example of a program that uses strftime() to return the current date in the format YYYY-mm-dd HH:MM:SS:
This call to strftime() assigns the current date and time, formatted as a string, to value. Here is an example of the date and time that are returned:
When you use strftime(), you must supply a format for your date time string. This format consists of one or more format specifiers and any other text you want to provide. Each format specifier consists of a % character followed by a single letter, and indicates one time component to be included in your format. The following table lists some of the most commonly used format specifiers:
For a complete list of the available format specifiers, and the other functions that are included in the Python time module, see the description of the time module in the Python online documentation. For examples of how to use strftime() in your scripts, see the Date and Time Manipulation section of the manual.
|