java中时间差计算
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+"年前";
}*/
java中时间差计算的更多相关文章
- JAVA中精确计算金额BigDecimal
package com.chauvet.utils; import java.math.BigDecimal; import java.text.DecimalFormat; import java. ...
- java第二周的学习知识4(对原码,补码,反码和java中浮点数计算不准确的总结)
原码:一个正数,转换为二进制位就是这个正数的原码.负数的绝对值转换成二进制位然后在高位补1就是这个负数的原码. 但是原码有几个缺点,零分两种 +0 和 -0 .很奇怪是吧!还有,在进行不同符号的加法运 ...
- Java中数学计算的相关方法
1:Math类 2.BigInteger类 3.BigDecimal类 BigInteger bi = new BigInteger("12433241123"); BigDec ...
- Java 中如何计算两个字符串时间之间的时间差?(单位为分钟)
Java 中如何计算两个字符串时间之间的时间差?(单位为分钟) import java.text.DateFormat; import java.text.ParseException; import ...
- JAVA中计算两个日期时间的差值竟然也有这么多门道
上半年春招的时候,作为面试官,对于面试表现的不错的同学会要求其写一小段代码看看.题目很简单: 给定一个日期,然后计算下距离今天相差的天数. 本以为这么个问题就是用来活跃面试氛围的,但是结果却让人大跌眼 ...
- Java中Double类型计算问题
public class Test{ public static void main(String args[]){ System.out.println(0.05+0.01); ...
- Java中的Double类型计算
一.问题的提出: 如果我们编译运行下面这个程序会看到什么?public class Test{ public static void main(String args[]){ Sy ...
- java中float/double浮点数的计算失精度问题(转)
如果我们编译运行下面这个程序会看到什么? public class Test { public static void main(String args[]) { ...
- 【Java编程】Java中的大整数计算
在上一篇文章中,我们实现了c语言中的大整数的运算,并且用Miller-Rabin算法实现了对大素数的测试.本来我准备用Java代码实现大整数的运算,查了一下资料发现Java中java.math的Big ...
随机推荐
- 【ArcGIS Server 开发系列】Flyingis六大系列讲座精品PDF奉献
转自:http://www.cnblogs.com/gispeng/archive/2008/07/24/1250116.html [ArcGIS Server 开发系列]Flyingis六大系列讲座 ...
- (转载)js----对象直接量
(转载)http://blog.csdn.net/greymouseyu/article/details/4015676 对象直接量提供了另一种创建新对象的方式.对象直接量允许将对象描述文字嵌入到Ja ...
- HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))
Equation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDOJ -- 4699
Editor Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Su ...
- Tree HDOJ--2682
Tree Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- A. Difference Row
A. Difference Row time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 常用开源GIS项目
常用开源GIS项目 常用开源桌面GIS软件 QGIS 始于2002年5月,算得上是开源GIS平台中的后起之秀.界面友好,分析功能可与GRASS GIS相媲美.主页:http://www.qgi ...
- light oj 1019【最短路模板】
1019 - Brush (V) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Tanvir r ...
- cf754D
题意:给你一个数m,有多少优惠券,给个n,主角想用多少优惠券.然后接下来时m行,每行两个数,那张优惠券的优惠区间a,b(在a号货物到b号货物之间的所有都可以优惠) 问你,能不能用k张优惠券,是他的优惠 ...
- java消息队列使用场景
http://blog.163.com/sir_876/blog/static/11705223201332444647261/ 目前能用到的比较不错的消息队列组件 ,kafka,activeMq, ...