Name

strftime, Format

Synopsis

                           d.strftime(fmt="%c”)

Returns a string representing d as specified by string fmt. The syntax of fmt is the same as in time.strftime, covered in Section 12.1 earlier in this chapter, but not all specifiers are meaningful. The result of d .strftime does not reflect the sign of the time interval that d represents; to display the sign as well, you must affix it to the string by separate string manipulation. For example:

if d.seconds >= 0.0: return d.strftime(fmt)
else: return '-' + d.strftime(fmt)

Format is a synonym of strftime.

Get Python in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.