Parse ISO 8601 dates in Python

Quick question-answer for today:

Q: How to parse an ISO 8601 date in Python?

A: Use dateutils Use the iso8601 module Use strptime:

*time.strptime(my_date,"%Y-%m-%dT%H:%M:%S")[:6]
I spent quite some time looking for an easy answer to this, but all the suggested modules I got where either buggy and not maintained anymore, or so old so that they were not even available on pip. So, this one liner was the best solution in the end.

PD: Beware of timezones! This works assuming you're using UTC.

3 comments:

  1. The problem is that you provide may be worth our time and also effort.
    Web Development Solution

    ReplyDelete
  2. You can read more about how hub pages work, here.
    xenforo designs

    ReplyDelete
  3. The blog is unique that’s providing the nice material. Please post more interesting articles here.
    Gentlemen

    ReplyDelete