Elegant algorithm for conversation line strings?

Possible duplicate:
How to calculate the relative time?

Given the DateTime object, what is the most elegant way you found to convert it to a human-friendly string. Something like that:

(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.

+3
source share
2 answers

, , , , . ( ).

+1

if-thens, . ( , ).

EDIT: . .

0

Source: https://habr.com/ru/post/1720135/


All Articles