Beautifier.java

 1package de.gultsch.chat.utils;
 2
 3import java.text.SimpleDateFormat;
 4import java.util.Date;
 5
 6public class Beautifier {
 7	public static String readableTimeDifference(long time) {
 8		if (time==0) {
 9			return "just now";
10		}
11		Date date = new Date(time);
12		long difference = (System.currentTimeMillis() - time) / 1000;
13		if (difference<60) {
14			return "just now";
15		} else if (difference<60*10) {
16			return difference / 60 + " min ago";
17		} else if (difference<60*60*24) {
18			SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
19			return sdf.format(date);
20		} else {
21			SimpleDateFormat sdf = new SimpleDateFormat("M/D");
22			return sdf.format(date);
23		}
24	}
25}