views:

180

answers:

7

My use case is that I'm just making a website that I want people all over the world to be able to use, and I want to be able to say things like "This happened at 5:33pm on October 5" and also "This happened 5 minutes ago," etc.

Should I use the datetime module? Or just strftime? Or something fancier that isn't part of the std distro of Python?

+2  A: 

Take a look at the dateutil module:

http://labix.org/python-dateutil

It's good at doing the types of things you're looking for - see some of the examples in the documentation.

ars
+1  A: 

If you're going to use datetime, make sure you read this recent and most excellent article: Tips on using python's datetime module. datetime will take care of most of the niceties of handling time arithmetic, but it won't give you the English-language pretty printing you're looking for.

Kamil Kisiel
A: 

I have always been very happy using the datetime package. You get a lot of stuff for free, and it's pretty easy to create datetime objects as well, calculate duration ect.

googletorp
A: 

There is also the Time module.

Key
Not very helpful... You'll never ever get things like "5 minutes ago" out of the time module.
tuergeist
+1  A: 

The datetime module in Python will allow you to get/set/manipulate dates and times. A question about relative date formatting in Python has already been asked: Stack Overflow Post but with very little responce.

kjfletch
+2  A: 

You may have a look at Django's humanize module.
It is part of Django, but I think it would be quite easy to adapt it to your needs.

Roberto Liffredo
+1  A: 

Try relativeDates Module module. It exactly brings you the stuff you wanted.

tuergeist