aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/gultsch/chat/utils/Beautifier.java
blob: 43b7acc2c704d0fb692bddde0d9afb59543f5a2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package de.gultsch.chat.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Beautifier {
	public static String readableTimeDifference(long time) {
		if (time==0) {
			return "just now";
		}
		Date date = new Date(time);
		long difference = (System.currentTimeMillis() - time) / 1000;
		if (difference<60) {
			return "just now";
		} else if (difference<60*10) {
			return difference / 60 + " min ago";
		} else if (difference<60*60*24) {
			SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
			return sdf.format(date);
		} else {
			SimpleDateFormat sdf = new SimpleDateFormat("M/D");
			return sdf.format(date);
		}
	}
}