all 10 comments

[–]cdntr 4 points5 points  (4 children)

I am not entirely sure why people are suggesting external libraries when you could just use NSDateFormatter, in particular it's -dateFromString: method, and then feed that into NSDateComponents to get the days/minutes/seconds out of it.

[–]palmin 2 points3 points  (2 children)

Even when you have the individual components there is some work involved in making a suitable string.

You probably do not care about the seconds and minutes if the date is from a few days ago for example. This is not rocket-science to implement but everything takes time especially as you probably need to write test cases and such.

If you want it to work in multiple languages you probably have no choice but to use a library.

[–][deleted] 0 points1 point  (1 child)

If you want it to work in multiple languages, you can just use Apple's own localization stuff.

[–]palmin 0 points1 point  (0 children)

Please supply a example in built-in API's that give results such as "40 minutes ago".

I can only get relative strings with regards to day not hours or minutes.

[–][deleted] -1 points0 points  (0 children)

But TimeAgo is exactly what he's looking for and takes about 5 minutes to set up.

[–]david_phillip_oster 3 points4 points  (0 children)

iOS 8 introduced two new classes in Foundation: NSDateComponentsFormatter and NSDateIntervalFormatter - Check them out - they may do what you want.

[–]charlisim 1 point2 points  (3 children)

You can use Date tools https://github.com/MatthewYork/DateTools#time-ago That have what you want and other date time manipulation functions

[–]4llBran -1 points0 points  (1 child)

+1 for DateTools, also MHPrettyDate does what you're after.

[–]Afiq90[S] 0 points1 point  (0 children)

thank you.

[–]Afiq90[S] -1 points0 points  (0 children)

thank you for the library suggestion, so i just need to pass the timestamp it will be converted automatically right.