2011-08-12 99 views

回答

1

是的。

>>> datetime.datetime.strptime("10/22/1984", "%m/%d/%Y") 
datetime.datetime(1984, 10, 22, 0, 0) 
0

第一次導入日期時間,然後嘗試將工作。

從日期時間的日期時間輸入日期 = datetime.strptime('10 /1984分之22' , '%d /%米/%Y')

1

我相信有許多簡單的方法。這裏是一個:「一個簡單的方法」

import re 
import datetime 

my_date = '10/22/1984' 
date_components = re.compile(r'(?P<month>\d+)/(?P<day>\d+)/(?P<year>\d+)') 
matched_date_components = date_components.match(my_date) 
date_time_object = datetime.date(year=matched_date_components.year, 
           month=matched_date_components.month, 
           day=matched_date_components.day) 
+0

看着其他的答案,我明顯感到困惑,並認爲這個問題提問者想「以複雜的方式」不但是,隨着「以艱難的方式學習python」的成功,也許我會得到一些硬核硬派投票的同情。 – Profane

+1

這是我的同情投票。 +1 –

+0

哈哈,非常感謝 – Profane