Android examples for java.util:Date Format
Display date value in XXX ago
import android.os.Build; import android.text.format.DateFormat; import java.text.Normalizer; public class Main{ public static String date2ago(long date, long now) { long seconds = now - date; if (seconds < 60) { return "moments ago"; } else if (seconds < 60 * 60) { return (seconds / 60) + " minutes ago"; } else if (seconds < 60 * 60 * 12) { return (seconds / 60 / 60) + " hours ago"; } else {/* ww w . jav a2 s. c o m*/ return DateFormat.format("EEEE, h:mmaa", date * 1000) .toString(); } } }