java中时间差计算
2024-08-29 22:15:31
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+"年前";
}*/
最新文章
- MapRedue开发实例
- mvc 中关于资源文件的扩展
- 【转】【MySql】mysql存储过程中的异常处理
- paper 112:hellinger distance
- ReentrantLock的使用
- Clearing Search Values
- 关于git reset和git revert之前的区别
- PHPUnit测试
- 将 Web 应用性能提高十倍的10条建议
- jquery的clone办法bug修复
- 步步详解近期大火的density_peak超赞聚类
- ECMAScript 6 笔记(六)
- CentOS、Ubuntu配置网卡子接口
- 关于Python的super用法研究
- idea 从git上checkout项目下来,project没有文件目录结构
- [20190213]测试服务端打开那些端口.txt
- 关于istream_iterator<;int>;(cin)和istream_iterator<;int>;()的一点分析
- linux后台运行命令:&;和nohup
- #2 安装Python
- wget一个网站很慢的原因