dateutil.parser.parse 接受 default 参数,您可以使用该参数指定参考日期:
import datetime as DT
import dateutil.parser as DP
today = DT.datetime(2016, 4, 13)
for text in ('today', 'tomorrow', 'this Sunday', 'Wednesday next week',
'next week Wednesday',
'next thursday', 'next tuesday in June', '11/28',
'Concert this Saturday'
"lunch with Andrew @ Mon Mar 7, 2016",
'meeting on Tuesday, 3/29'):
dp_date = DP.parse(text, default=today, fuzzy=True)
print('{:35} --> {}'.format(text, dp_date))
产量
today --> 2016-04-13 00:00:00
tomorrow --> 2016-04-13 00:00:00 should be 2016-04-14
this Sunday --> 2016-04-17 00:00:00
Wednesday next week --> 2016-04-13 00:00:00
next week Wednesday --> 2016-04-13 00:00:00
next thursday --> 2016-04-14 00:00:00
next tuesday in June --> 2016-06-14 00:00:00 should be 2016-06-07
11/28 --> 2016-11-28 00:00:00
Concert this Saturday --> 2016-04-16 00:00:00
lunch with Andrew @ Mon Mar 7, 2016 --> 2016-03-07 00:00:00
meeting on Tuesday, 3/29 --> 2016-03-29 00:00:00
但请注意,并非所有短语都被正确解析。