Parse Datetime Strings with parsedatetime in Python
Introduction
In this tutorial, we’ll take a look at how to parse Datetime with parsedatetime
in Python.
To use the parsedatetime
package we first need to install it using pip:
$ pip install parsedatetime
Should pip install parsedatetime
fail, the package is also opensource available on Github.
Convert String to Python’s Datetime Object with parsedatetime
The first, and most common way to use parsedatetime
is to parse a string into a datetime
object. First, you’ll want to import the parsedatetime
library, and instantiate a Calendar
object, which does the actual input, parsing and manipulation of dates:
import parsedatetime
calendar = parsedatetime.Calendar()
Now we can call the parse()
method of the calendar
instance with a string as an argument. You can put in regular datetime-formatted strings, such as