public class DateUtils {
private static long minute = 1000 * 60;
private static long hour = minute * 60;
private static long day = hour * 24;
private static long halfamonth = day * 15;
private static long month = day * 30;
public static String getDateDiff(long dateTimeStamp){
String result;
long now = new Date().getTime();
long diffValue = now - dateTimeStamp;
if(diffValue < 0){
//toast("结束日期不能小于开始日期!");
}
long monthC =diffValue/month;
long weekC =diffValue/(7*day);
long dayC =diffValue/day;
long hourC =diffValue/hour;
long minC =diffValue/minute;
if(monthC>=1){
result="发表于" + Integer.parseInt(monthC+"") + "个月前";
return result;
}
else if(weekC>=1){
result="发表于" + Integer.parseInt(weekC+"") + "周前";
return result;
}
else if(dayC>=1){
result="发表于"+ Integer.parseInt(dayC+"") +"天前";
return result;
}
else if(hourC>=1){
result="发表于"+Integer.parseInt(hourC+"") +"个小时前";
return result;
}
else if(minC>=1){
result="发表于"+ Integer.parseInt(minC+"") +"分钟前";
return result;
}else{
result="刚刚发表";
return result;
}

}

}

更多相关文章

  1. 将日期保存到序列化文件
  2. 当月的开始和结束日期
  3. Windows中结束占用某个端口的进程
  4. java 计算两个日期间的所有日期
  5. 黑马程序员 Java中根据YYYY-MM-DD格式的日期计算为星期几的两种

随机推荐

  1. 使用response.sendirect("html/employee.
  2. 从html文档中解析数据()[重复]
  3. 如何在离子框架中显示图像标题?
  4. CGI编程学习5 穿插HTML,CSS零星知识
  5. html5结合flash实现视频文件在所有主流浏
  6. DOM笔记(三):Element接口和HTMLElement接口
  7. [原创]基于html5新标签canvas写的一个小
  8. 大熊君学习html5系列之
  9. web前端2016-3-5
  10. iis aspx常见错误 HTTP 错误 404 - 文件