datetime-parsing

Parsing time string in Python

Parsing time string in Python Question: I have a date time string that I don’t know how to parse it in Python. The string is like this: Tue May 08 15:14:45 +0800 2012 I tried datetime.strptime(“Tue May 08 15:14:45 +0800 2012″,”%a %b %d %H:%M:%S %z %Y”) but Python raises ‘z’ is a bad directive in …

Total answers: 5

How do I translate an ISO 8601 datetime string into a Python datetime object?

How do I translate an ISO 8601 datetime string into a Python datetime object? Question: I’m getting a datetime string in a format like “2009-05-28T16:15:00” (this is ISO 8601, I believe). One hackish option seems to be to parse the string using time.strptime and passing the first six elements of the tuple into the datetime …

Total answers: 11

How can I parse a time string containing milliseconds in it with python?

How can I parse a time string containing milliseconds in it with python? Question: I am able to parse strings containing date/time with time.strptime >>> import time >>> time.strptime(’30/03/09 16:31:32′, ‘%d/%m/%y %H:%M:%S’) (2009, 3, 30, 16, 31, 32, 0, 89, -1) How can I parse a time string that contains milliseconds? >>> time.strptime(’30/03/09 16:31:32.123′, ‘%d/%m/%y …

Total answers: 7

Natural/Relative days in Python

Natural/Relative days in Python Question: I’d like a way to show natural times for dated items in Python. Similar to how Twitter will show a message from “a moment ago”, “a few minutes ago”, “two hours ago”, “three days ago”, etc. Django 1.0 has a “humanize” method in django.contrib. I’m not using the Django framework, …

Total answers: 6