Java tutorial
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String getDisplayDateTime(Long time) { String ret; if (time < getYearStart()) { ret = getTimeYMDHM(new Date(time)); } else { ret = getTimeMDHM(new Date(time)); } return ret; } public static long getYearStart() { Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_YEAR, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTimeInMillis(); } public static String getTimeYMDHM(Date inputDate) { return new SimpleDateFormat("yyyy-MM-dd E HH:mm").format(inputDate); } public static String getTimeYMDHM(Long inputDate) { if (inputDate == null) { return null; } return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date(inputDate)); } public static String getTimeMDHM(Date inputDate) { return new SimpleDateFormat("E MM-dd HH:mm").format(inputDate); } public static String getTimeMDHM(Long inputDate) { return new SimpleDateFormat("MM-dd HH:mm").format(new Date(inputDate)); } }