擅长:python、mysql、java
<p>感谢@David Cain的评论回复:</p>
<blockquote>
<p>The dateutil library can parse datetime strings (inferring their format). However, note that "11/5/2003" is not an unambiguous format (MM/DD or DD/MM differs by locale), so dateutil should be used with caution in this case. – David Cain</p>
</blockquote>
<p>因此,另一个好的做法是使用dateutil库:</p>
<pre><code>>>> from dateutil.parser import parse
>>> dt = parse('2016/12/05 05:18 pm')
>>> dt
datetime.datetime(2016, 12, 5, 17, 18)
>>> dt.timestamp()
1480929480.0
>>> parse('16/11/12')
>>> datetime.datetime(2012, 11, 16, 0, 0)
</code></pre>