通过在Ubuntu 12.04上使用Python 2.7上的parsedatetime库。当传递包含字符但没有有效日期(或时间)的字符串时,parse()函数有时会返回有效的日期/时间。确保parsedatetime不分析无效的日期/时间字符串
提交问题48后,它看起来像parsedatetime真的不想要一个没有日期/时间的字符串。
那么,想要在预处理器上确定布尔值是否包含有效的日期字符串?
参考链接: https://github.com/bear/parsedatetime/ https://code.google.com/p/parsedatetime/issues/detail?id=48
注:在第48期我召唤出parseDateText()是不合适的。我已经确认与parse()存在相同的操作。
任何帮助,非常感谢。
编辑:示例代码。
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import parsedatetime as pdt
>>> c = pdt.Constants()
>>> c.BirthdayEpoc = 80
>>> p = pdt.Calendar(c)
>>> print p.parse("Mary had a little lamb.")
((2014, 3, 1, 20, 53, 56, 6, 69, 1), 1)
>>> print p.parse("foo bar")
(time.struct_time(tm_year=2013, tm_mon=3, tm_mday=10, tm_hour=20, tm_min=54, tm_sec=6, tm_wday=6, tm_yday=69, tm_isdst=1), 0)
>>> print p.parse("March 12th, 2013")
((2013, 3, 12, 20, 54, 34, 6, 69, 1), 1)
>>>
提供一个完整的示例来说明问题。您可能想要提交使用'parse()'方法的另一个问题。 – jfs 2013-03-10 21:46:50
好吧,我会这样做的。谢谢。 – user2154772 2013-03-11 00:54:14