ID EN
Time

strftime

Python 3.11

Convert a tuple or struct_time representing a time as returned by gmtime() or localtime() to a string as specified by the format argument. If t is not provided, the current time as returned by localtime() is used. format must be a string. ValueError is raised if any field in t is outside of the allowed range.

Syntax

PYTHON
time.strftime(format[, t])

Examples

Example 1
PYTHON
>>> from time import gmtime, strftime
>>> strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
'Thu, 28 Jun 2001 14:17:15 +0000'

See Also

struct_time gmtime() localtime() localtime() ValueError strftime() strptime() strftime()