3

Possible Duplicate:
How do I calculate relative time?

Given a DateTime object, what's the most elegant way you've found of converting it to a human friendly string. Something like this:

(Future)

"Tomorrow"
"[1|2|3|4|5|6] days from now."
"Next week"
"Next month"

(Past)
"[1|2|3|4|5|6] days ago."
"Last week"
"Last month"

Thanks.

1

2 Answers 2

1

It's not necessarily the most elegant solution, but this blog article, as well as the the first comment, solve the problem as it pertains to dates in the past. (Copying and pasting the first comment requires replacing the fancy double quotes with plain-old double quotes.)

Sign up to request clarification or add additional context in comments.

Comments

0

Stack Overflow just uses cascading if-thens I believe. Can't find the post right now (it's either here or on meta).

EDIT: Jason found it. Link in the comments on the question.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.