Display relative time in hour, day, month and year
- by JohnJohnGa
I wrote a function
toBeautyString(epoch) : String
which given a epoch, return a string which will display the relative time from now in hour and minute
For instance:
// epoch: 1346140800 -> Tue, 28 Aug 2012 05:00:00 GMT
// and now: 1346313600 -> Thu, 30 Aug 2012 08:00:00 GMT
toBeautyString(1346140800)
-> "2 days and 3 hours ago"
I want now to extend this function to month and year, so it will be able to print:
2 years, 1 month, 3 days and 1 hour ago
Only with epoch without any external libraries.
The purpose of this function is to give to the user a better way to visualize the time in the past.
I found this: Calculating relative time but the granularity is not enough.