Copyright © tutorialspoint.com

Python time strftime() Function

previous next


Description:

This function converts 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. An exception ValueError is raised if any field in t is outside of the allowed range.

Syntax:

time.strftime(format[, t])

Parameters:

Here is the detail of parameters:

Directive:

Example:

#!/usr/bin/python
import time

t = (2009, 2, 17, 17, 3, 38, 1, 48, 0)
t = time.mktime(t)
print time.strftime("%b %d %Y %H:%M:%S", time.gmtime(t))

This produces following result:

Feb 18 2009 00:03:38

previous next

Copyright © tutorialspoint.com