Python: Parse ISO 8601 date and time from string (using standard modules)

I want to parse the SVN record date:

svn list --xml https://subversion:8765/svn/Foo/tags/ 

If I am not mistaken, it is provided using the ISO 8601 standard . Example:

 dateString = "2012-02-14T11:22:34.593750Z" 

I am using Python 2.7 and I am looking for a better way to handle using only standard modules. I think I will parse it this way using the regular expression: ^--- is a matching group, and A means that I will assume that they always exist (which could be a weakness)

 dateString = "2012-02-14T11:22:34.593750Z" ^--- ^- ^-A^- ^- ^--------A | | | I think it always gives the date | as UTC, which Z means in ISO 8601. | Just a separator 

After parsing it, I just create a datetime from it.

Is there a better way to use Python 2.7 with standard modules only?

+4
source share
1 answer

No regex is needed, use datetime.datetime.strptime() instead.

+7
source

Source: https://habr.com/ru/post/1398019/


All Articles