Here you can find the source of time2String(long time)
public static String time2String(long time)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String time2String(long time) { SimpleDateFormat df = new SimpleDateFormat("yy-MM-dd HH:mm"); Calendar toyear = Calendar.getInstance(); Calendar today = Calendar.getInstance(); toyear.set(Calendar.MONTH, Calendar.JANUARY); toyear.set(Calendar.DATE, 1); toyear.set(Calendar.HOUR_OF_DAY, 0); toyear.set(Calendar.MINUTE, 0); toyear.set(Calendar.SECOND, 0); today.set(Calendar.HOUR_OF_DAY, 0); today.set(Calendar.MINUTE, 0); today.set(Calendar.SECOND, 0); if (time > toyear.getTime().getTime() && time < today.getTime().getTime()) df = new SimpleDateFormat("MM-dd"); else if (time > today.getTime().getTime()) df = new SimpleDateFormat("HH:mm"); return df.format(new Date(time)); }//from w w w . ja va2 s . co m }