MomentJS is similar to functionality for Android applications

I have a record with a date and time, and I would like to convert the transaction date from the current date, differentiate and show the number of days.

For example,

If the date time is set in the record, which is 1 hour earlier than now, the system should show an hour ago ...

Similarly, if there is a record 3 days before, instead of showing the date, I would like to show “3 days ago”.

+8
android
source share
2 answers

No need to use any custom solution.

You can use android.text.format.DateUtils.getRelativeTimeSpanString

It returns a string describing "time" as time relative to "now."

link: http://developer.android.com/reference/android/text/format/DateUtils.html

+8
source share

Hi, you can use this lib for java:

http://www.ocpsoft.org/prettytime/

Also if you want lib for xml layouts, where are other libraries that might help you:

https://github.com/curioustechizen/android-ago

0
source share

All Articles