Copyright © tutorialspoint.com

Python time strptime() Function

previous next


Description:

This function parses a string representing a time according to a format. The return value is a struct_time as returned by gmtime() or localtime().

The format parameter uses the same directives as those used by strftime(); it defaults to "%a %b %d %H:%M:%S %Y" which matches the formatting returned by ctime().

If string cannot be parsed according to format, or if it has excess data after parsing, ValueError is raised.

Syntax:

time.strptime(string[, format])

Parameters:

Here is the detail of parameters:

Directive:

Example:

#!/usr/bin/python
import time

struct_time = time.strptime("30 Nov 00", "%d %b %y")
print "returned tuple: %s " % struct_time

This produces following result:

returned tuple: (2000, 11, 30, 0, 0, 0, 3, 335, -1)

previous next

Copyright © tutorialspoint.com