本文转自:http://blog.csdn.net/Aarchbishop/archive/2006/04/30/699000.aspx
>>> import time
>>> import datetime
>>> now = time.localtime()
>>> now
(2006, 4, 30, 18, 7, 35, 6, 120, 0)
>>> type(now)
>>> str_now = time.strftime("%m/%d/%Y %X", now )
>>> str_now
'04/30/2006 18:07:35'
>>> new_now = time.strptime( str_now, "%m/%d/%Y %X" )
>>> new_now
(2006, 4, 30, 18, 7, 35, 6, 120, -1)
这里,strftime 将 struct_time 的时间按指定的格式转化成 字符串
strptime 将 字符串按指定的格式转化成 struct_time 的时间
struct_time 的时间没有现成的比较的函数,可以将 struct_time 转化成 datetime.datetime
>>> d_now = datetime.datetime( *now[:6] )
>>> type(d_now)
>>> d_now
datetime.datetime(2006, 4, 30, 18, 7, 35)