Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 24367

Python Morsels: Converting a string to a datetime

$
0
0

The datetime.strptime class method can parse a date/time string into a datetime object.

Parsing strings into datetime objects ➡️

Here's an example of the strptime class method in action:

>>> fromdatetimeimportdatetime>>> datetime.strptime("Jun 1 2005  1:33PM","%b %d %Y %I:%M%p")datetime.datetime(2005, 6, 1, 13, 33)

Note that strptime is a class method: we're calling it on the datetime class (not an instance of the class).

The strptime formatting directives 📑

Those single letter % codes …

Read the full article: https://www.pythonmorsels.com/converting-a-string-to-a-datetime/


Viewing all articles
Browse latest Browse all 24367

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>