Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python time strptime() method

Python time strptime() method


Description

The Python time strptime() function parses a time string into a time tuple according to the specified format.

Syntax

strptime() method syntax:



time.strptime(string[, format])

Parameters

Return Value

Returns a struct_time object.

Description

Date and time formatting symbols in Python:

Example

The following example shows how to use the strptime() function:

Example (Python 2.0+)

#!/usr/bin/python

-- coding: UTF-8 --

import

time

struct_time

=

time

.

strptime

(

"

30 Nov 00

"

,

"

%d %b %y

"

)

print

"

Returned tuple: %s

"

%

struct_time

The output of the above example is:



返回的元组: time.struct_time(tm_year=2000, tm_mon=11, tm_mday=30, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=335, tm_isdst=-1)