2011-10-31 85 views

回答

0

datetime module可能是你想要的。

下面是一個例子:

>>> from datetime import datetime, timedelta 
>>> s = raw_input('Input year month day hour minute second: ') 
Input year month day hour minute second: 2011 10 31 14 30 00 
'2011 10 31 14 30 00' 
>>> fields = map(int, s.split()) 
>>> fields 
[2011, 10, 31, 14, 30, 0] 
>>> userdate = datetime(*[2011, 10, 31, 14, 30, 0]) 
>>> userdate 
datetime.datetime(2011, 10, 31, 14, 30) 
>>> userdate - timedelta(days=20) 
datetime.datetime(2011, 10, 11, 14, 30) 

>>> now = datetime.now() 
>>> now 
datetime.datetime(2011, 10, 31, 11, 38, 34, 856511) 
>>> now + timedelta(hours=2) 
datetime.datetime(2011, 10, 31, 13, 38, 34, 856511)