Quantcast
Channel: Convert string "Jun 1 2005 1:33PM" into datetime - Stack Overflow
Viewing all articles
Browse latest Browse all 55

Answer by jjm for Converting string into datetime

$
0
0

If your string is in ISO8601 format and you have Python 3.7+ you can use the following simple code:

import datetime.dateaDate = datetime.date.fromisoformat('2020-10-04')

for dates and

import datetime.datetimeaDateTime = datetime.datetime.fromisoformat('2020-10-04 22:47:00')

for strings containing date and time. If timestamps are included the function datetime.datetime.isoformat() supports the following format

YYYY-MM-DD[*HH[:MM[:SS[.fff[fff]]]][+HH:MM[:SS[.ffffff]]]]

where * matches any single character. See also here and here


Viewing all articles
Browse latest Browse all 55

Trending Articles



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