1

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?

Josh Gibson
  • 21,808
  • 28
  • 67
  • 63

7 Answers7

2

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
  • 120,335
  • 23
  • 147
  • 134
2

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.

rob
  • 36,896
  • 2
  • 55
  • 65
1

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
  • 19,723
  • 11
  • 46
  • 56
1

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.

Community
  • 1
  • 1
kjfletch
  • 5,394
  • 3
  • 32
  • 38
1

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

tuergeist
  • 9,171
  • 3
  • 37
  • 58
0

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
  • 33,075
  • 15
  • 67
  • 82
0

There is also the Time module.

Key
  • 6,986
  • 1
  • 23
  • 15