public class Utill {
public String TimeString(Date currentTime, Date beginTime){
/*默认为毫秒,除以1000是为了转换成秒*/
long interval=(currentTime.getTime()-beginTime.getTime())/1000;//秒
if(interval<0){
interval=-interval;
}
long temp=0;
String result;
if(interval<60){
return result="just";
}else if((temp = interval/60)<60){
return result=temp+(temp==1?" minute ago":" minutes ago");
}else if((temp = temp/60) <24){
return result=temp+(temp==1?" hour ago":" hours ago");
}else if((temp = temp/24) <30){
return result=temp+(temp==1?" day ago":" days ago");
}else if((temp = temp/30) <12){
return result=temp+(temp==1?" month ago":" months ago");
}else{
temp = temp/12;
result=temp+(temp==1?" year ago":" years ago");
}
return result;
}
/*if(interval<60){
return result="刚刚";
}else if((temp = interval/60)<60){
return result=temp+"分钟前";
}else if((temp = temp/60) <24){
result = temp+"小时前";
}else if((temp = temp/24) <30){
result = temp+"天前";
}else if((temp = temp/30) <12){
result = temp+"月前";
}else{
temp = temp/12;
result = temp+"年前";
}*/

最新文章

  1. MapRedue开发实例
  2. mvc 中关于资源文件的扩展
  3. 【转】【MySql】mysql存储过程中的异常处理
  4. paper 112:hellinger distance
  5. ReentrantLock的使用
  6. Clearing Search Values
  7. 关于git reset和git revert之前的区别
  8. PHPUnit测试
  9. 将 Web 应用性能提高十倍的10条建议
  10. jquery的clone办法bug修复
  11. 步步详解近期大火的density_peak超赞聚类
  12. ECMAScript 6 笔记(六)
  13. CentOS、Ubuntu配置网卡子接口
  14. 关于Python的super用法研究
  15. idea 从git上checkout项目下来,project没有文件目录结构
  16. [20190213]测试服务端打开那些端口.txt
  17. 关于istream_iterator&lt;int&gt;(cin)和istream_iterator&lt;int&gt;()的一点分析
  18. linux后台运行命令:&amp;和nohup
  19. #2 安装Python
  20. wget一个网站很慢的原因

热门文章

  1. javascript时间、随机数
  2. CentOS下date命令 - 显示和设置系统日期与时间
  3. Flume FileChannel优化(扩展)实践指南
  4. Unity给力插件之MeshBaker
  5. 【转】如何实现一个malloc
  6. 关于升级linux下apache
  7. fatal error LINK1123:failure during conversion to COFF:file invalid or corrupt
  8. Intent是什么?
  9. macos下使用rvm管理ruby版本和rails版本
  10. Android APK反编译具体解释(附图)