/**
*
* @param timeMills
* 格式化时间
* @param currentMills
* 当前时间
* @return 时间日期显示,返回的格式有yy-MM-dd,星期几 如果要显示几天前,几分钟前,几秒前请使用DateUtils的相关方法
*/
public static String formatDateDisplayStyle(long date, long currentMills, Context context) {
Resources r = Resources.getSystem();
Locale locale = Locale.getDefault();
SimpleDateFormat sdf = null;
String returnStr = null;
int resId;
boolean past = (currentMills >= date);
long duration = currentMills - date;
long absDuration = Math.abs(duration);
returnStr += "past=" + past + "||absDuration=" + absDuration;
//如果大于当前时间或者在一个星期之前
if (!past || absDuration > WEEK_IN_MILLIS) {
if (locale.equals(Locale.CHINA)) {
sdf = new SimpleDateFormat("yy-M-d");
} else {
sdf = new SimpleDateFormat("M/d/yy");
}
returnStr = sdf.format(new Date(date));
return returnStr;
} else {
//如果是在24小时之内
if (absDuration < DAY_IN_MILLIS) {
Log.i("liyong","===24小时之内");
if (DateFormat.is24HourFormat(context)) {
Log.i("liyong", "====24小时制");
sdf = new SimpleDateFormat("H:MM");
} else {
locale.setDefault(Locale.ENGLISH);
if (locale.equals(Locale.CHINA)) {
Log.i("liyong", "====12中国片区");
sdf = new SimpleDateFormat("a hh:mm");
} else {
Log.i("liyong", "====12非中国片区");
sdf = new SimpleDateFormat("h:MM a");
}
}
Log.i("liyong", "new Date(date)=" + new Date(date));
returnStr = sdf.format(new Date(date));
Log.i("liyong", "returnStr=" + returnStr);
//如果是在24 -- 48小时之内
} else if (absDuration > DAY_IN_MILLIS && absDuration <= TWODAYS_IN_MILLIS) {
//resId = com.android.internal.R.plurals.abbrev_num_days_ago;
//returnStr = r.getQuantityString(resId, (int) 1);
//如果是在48 - 一个星期
} else if (absDuration > TWODAYS_IN_MILLIS && absDuration <= WEEK_IN_MILLIS) {
sdf = new SimpleDateFormat("EEEE");
returnStr = sdf.format(new Date(date));
}
}
return returnStr;
}
*
* @param timeMills
* 格式化时间
* @param currentMills
* 当前时间
* @return 时间日期显示,返回的格式有yy-MM-dd,星期几 如果要显示几天前,几分钟前,几秒前请使用DateUtils的相关方法
*/
public static String formatDateDisplayStyle(long date, long currentMills, Context context) {
Resources r = Resources.getSystem();
Locale locale = Locale.getDefault();
SimpleDateFormat sdf = null;
String returnStr = null;
int resId;
boolean past = (currentMills >= date);
long duration = currentMills - date;
long absDuration = Math.abs(duration);
returnStr += "past=" + past + "||absDuration=" + absDuration;
//如果大于当前时间或者在一个星期之前
if (!past || absDuration > WEEK_IN_MILLIS) {
if (locale.equals(Locale.CHINA)) {
sdf = new SimpleDateFormat("yy-M-d");
} else {
sdf = new SimpleDateFormat("M/d/yy");
}
returnStr = sdf.format(new Date(date));
return returnStr;
} else {
//如果是在24小时之内
if (absDuration < DAY_IN_MILLIS) {
Log.i("liyong","===24小时之内");
if (DateFormat.is24HourFormat(context)) {
Log.i("liyong", "====24小时制");
sdf = new SimpleDateFormat("H:MM");
} else {
locale.setDefault(Locale.ENGLISH);
if (locale.equals(Locale.CHINA)) {
Log.i("liyong", "====12中国片区");
sdf = new SimpleDateFormat("a hh:mm");
} else {
Log.i("liyong", "====12非中国片区");
sdf = new SimpleDateFormat("h:MM a");
}
}
Log.i("liyong", "new Date(date)=" + new Date(date));
returnStr = sdf.format(new Date(date));
Log.i("liyong", "returnStr=" + returnStr);
//如果是在24 -- 48小时之内
} else if (absDuration > DAY_IN_MILLIS && absDuration <= TWODAYS_IN_MILLIS) {
//resId = com.android.internal.R.plurals.abbrev_num_days_ago;
//returnStr = r.getQuantityString(resId, (int) 1);
//如果是在48 - 一个星期
} else if (absDuration > TWODAYS_IN_MILLIS && absDuration <= WEEK_IN_MILLIS) {
sdf = new SimpleDateFormat("EEEE");
returnStr = sdf.format(new Date(date));
}
}
return returnStr;
}