all Python 3timefunction
time.strftime()
formatting
Formats a struct_time into a string using codes such as %Y, %m, %d, %H…; without the second argument it uses the current local time.
Syntax
time.strftime(format[, time_tuple])
It is a module function, not a method: the format comes first and the time second, and that time is a struct_time, not a datetime or a number of seconds. The codes are the same as for datetime.strftime, but struct_time keeps no fractions of a second: %f gives no microseconds here. Without the second argument the result depends on the machine's zone — pass gmtime() for UTC.
Examples
import time
t = time.gmtime(0)
print(time.strftime('%Y-%m-%d %H:%M:%S', t)) # → 1970-01-01 00:00:00
print(time.strftime('%d.%m.%y', t)) # → 01.01.70
print(time.strftime('%H:%M')) # → ? 14:05 — сейчас, местное время
See also
Open in the full glossarydocs.python.orgReport an inaccuracy