4

I want to parse the date for entries given by SVN:

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

If I am not mistaken it is given using the ISO 8601 standard. An example is:

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

I am using Python 2.7 and am looking for the best way to process is using the standard modules only. I think I´ll parse it this way using a regular expression: ^--- is a match group and A indicates that I will assume that they are always there (which might 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´ll simply create a datetime from it.

Is there a better way using Python 2.7 with only the standard modules?

unwind
  • 391,730
  • 64
  • 469
  • 606
Deleted
  • 1,351
  • 3
  • 14
  • 18
  • possible duplicate of [How do I translate a ISO 8601 datetime string into a Python datetime object?](http://stackoverflow.com/questions/969285/how-do-i-translate-a-iso-8601-datetime-string-into-a-python-datetime-object) – Kimvais Feb 23 '12 at 11:53
  • It is possible, it depends on what has happened between Python 2.5 (which the other ones uses) and Python 2.7. – Deleted Feb 23 '12 at 12:02

1 Answers1

8

No need for a regexp, use datetime.datetime.strptime() instead.

Kimvais
  • 38,306
  • 16
  • 108
  • 142
  • 2
    Thanks! I parsed it successfully using `datetime.datetime.strptime(date_string_to_parse, '%Y-%m-%dT%H:%M:%S.%fZ')`. I didn´t get it to parse the timezone (the Z) so I hard coded it as I think the output I´m parsing always will be using Z. – Deleted Feb 29 '12 at 14:51