Here you can find the source of getShortTimeText(Long oldTime)
@SuppressWarnings("deprecation") public static String getShortTimeText(Long oldTime)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public final static String TimeFormat = "yyyyMMddHHmmss"; public final static String DisplayDateFormat = "yyyy-MM-dd"; @SuppressWarnings("deprecation") public static String getShortTimeText(Long oldTime) { Date time = parseDate(oldTime, TimeFormat); Date now = new Date(); String format = "yyyy-MM-dd HH:mm"; if (time.getYear() == now.getYear()) { format = format.substring("yyyy-".length()); if (time.getMonth() == now.getMonth() && time.getDay() == now.getDay()) { format = format.substring("MM-dd ".length()); }/* w w w .j a v a2s .co m*/ } return formatDate(time, format); } public static Date parseDate(Long date, String format) { if (date == null) { return null; } SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.CHINA); try { return simpleDateFormat.parse(date + ""); } catch (ParseException e) { return null; } } public static Date parseDate(String date, String format) { if (date == null) { return null; } SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.CHINA); try { return simpleDateFormat.parse(date + ""); } catch (ParseException e) { return null; } } public static String formatDate(Date date, String format) { if (date == null) { return ""; } SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.CHINA); return simpleDateFormat.format(date); } public static String formatDate(Date date) { return formatDate(date, DisplayDateFormat); } }