I have a String like that : String date_annonce = "2014-06-12 17:25:43";
I would like to show in my app a text like : 10 min ago or 1h ago or 2d ago
It represent the difference from date_annonce and actual date.
How can i do this ?
I have a String like that : String date_annonce = "2014-06-12 17:25:43";
I would like to show in my app a text like : 10 min ago or 1h ago or 2d ago
It represent the difference from date_annonce and actual date.
How can i do this ?
see this DateUtil method
String relativeString = getRelativeDateTimeString (this, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS,DateUtils.WEEK_IN_MILLIS, 0));
you have to subtract System.currentTimeMillis()
from data_annonce
in milliseconds. To convert it milliseconds you can use SimpleDateFormat
to get a Date
object from the string.