public static String getSendedTime(long oldTime) {
String sTime = null;
long today0HourTime = getTodayTimeMillis();
if (oldTime < today0HourTime) {
long lTime = today0HourTime - oldTime;
int num = (int) (lTime / oneDay);
if (num >= 0 && num <2) {
sTime = strTime[num];
}else if(num >= 2 && num <= 6){
sTime = strTime[2];
}else{
sTime = getTimeByLong(oldTime, "M月d日");
}
} else {
sTime = getTimeByLong(oldTime, "HH:mm");
}
return sTime;
}
public static String getTimeByLong(long tLong, String format) {
String strDate = "";
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(tLong);
cal.setTimeZone(TimeZone.getTimeZone("GMT+8"));
SimpleDateFormat sdf = new SimpleDateFormat(format);
strDate = sdf.format(cal.getTime());
return strDate;
}
private static long getTodayTimeMillis() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTimeInMillis();
}
// *******************************************************
private final static long oneDay = 24 * 60 * 60 * 1000;
private static String[] strTime = { "昨天", "前天", "三天前" };
String sTime = null;
long today0HourTime = getTodayTimeMillis();
if (oldTime < today0HourTime) {
long lTime = today0HourTime - oldTime;
int num = (int) (lTime / oneDay);
if (num >= 0 && num <2) {
sTime = strTime[num];
}else if(num >= 2 && num <= 6){
sTime = strTime[2];
}else{
sTime = getTimeByLong(oldTime, "M月d日");
}
} else {
sTime = getTimeByLong(oldTime, "HH:mm");
}
return sTime;
}
public static String getTimeByLong(long tLong, String format) {
String strDate = "";
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(tLong);
cal.setTimeZone(TimeZone.getTimeZone("GMT+8"));
SimpleDateFormat sdf = new SimpleDateFormat(format);
strDate = sdf.format(cal.getTime());
return strDate;
}
private static long getTodayTimeMillis() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTimeInMillis();
}
// *******************************************************
private final static long oneDay = 24 * 60 * 60 * 1000;
private static String[] strTime = { "昨天", "前天", "三天前" };