![]() |
VOOZH | about |
time.strftime(format[, t]) function in Python's time module converts a given time tuple (t) or struct_time object into a formatted string based on the specified format. If t is not provided, the function uses the current local time. The format must be a string and a ValueError is raised if any field in t is out of range. Example:
2025-03-08 11:01:08
Syntax:
time.strftime(format[, t])
Parameters:
Returns: Returns a formatted string representing the time.
Points to remember:
Directive | Meaning | Example Output |
|---|---|---|
%a | Abbreviated weekday name | Tue |
%A | Full weekday name | Tuesday |
%b | Abbreviated month name | Jun |
%B | Full month name | June |
%c | Preferred date and time representation | Tue Jun 25 10:09:52 2019 |
%d | Day of the month (01-31) | 25 |
%H | Hour (00-23) | 10 |
%I | Hour (01-12) | 10 |
%j | Day of the year (001-366) | 176 |
%m | Month (01-12) | 06 |
%M | Minute (00-59) | 09 |
%S | Second (00-59) | 52 |
%U | Week number (Sunday as the first day) | 25 |
%W | Week number (Monday as the first day) | 25 |
%Y | Year with century | 2019 |
%y | Year without century (00-99) | 19 |
%Z | Time zone name | UTC |
%z | UTC offset | +0000 |
Example:
Output
Example 1: Sat, 08 Mar 2025 11:00:10 + 1010
Example 2: Saturday, 03/08/25 March 2025 11:00:10 + 0000
Example 3: Sat Mar 8 11:00:10 2025
Example 4: 20
Example 5: Saturday, 03/08/25 March 2025, 11:00:10 AM,
MOTY:03
DOTY:% j
Example 6: 11:00
Example 7: Sat, 08 Mar 2025 11:00:10 + 0000
Example 8: 11:00:10 AM, 11:00:10
Example 9: 11:00:10 AM, 6, 09
Example 10: 11:00:10 AM, 10, 09, 6
Example 11: 03/08/25, 11:00:10, 25, 2025
Example 12: 11:00:10 AM, +0000, UTC