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 ...
随机推荐
- GCC常用参数
GCC--GNU C Compiler c语言编译器(远不止c语言) 介绍: 作为自由软件的旗舰项目,Richard Stallman 在十多年前刚开始写作 GCC 的时候,还只是把它当作仅仅一个C ...
- 参考SQLHelper编写的OracleHelper
使用 Oracle.ManagedDataAccess.Client 类库参考SQLHelper编写的OracleHelper: // ================================ ...
- [App]Android Studio First App
准备着看Android Studio的体验如何. 通过Android Studio构建一个默认的项目,添加一些元素 <RelativeLayout xmlns:android="htt ...
- Bzoj 1982: [Spoj 2021]Moving Pebbles 博弈论
1982: [Spoj 2021]Moving Pebbles Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 130 Solved: 88[Submi ...
- parseSdkContent failed Could not initialize class android.graphics.Typeface
Deleting ".android" is temporarily fixing the problem with me as after sometime it begins ...
- oracle查看表锁及解锁
--kill session语句 1 alter system kill SESSION '2171,60490'; --以下几个为相关表 1 2 3 4 5 6 7 SELECT * FROM v$ ...
- RHEL6彻底禁用ip6的方法
一.vi /etc/modprobe.d/disable-ipv6.conf(名字随便起)(RHEL6.0之后没有了/etc/modprobe.conf这个文件) 输入:install ipv6 / ...
- First Adventures in Google Closure -摘自网络
Contents Introduction Background Hello Closure World Dependency Management Making an AJAX call with ...
- Java 字符转码之UTF-8转为GBK/GB2312
java跟python类似的做法,在java中字符串的编码是java修改过的一种Unicode编码,所以看到java中的字符串,心理要默念这个东西是java修改过的一种Unicode编码的编码. pa ...
- [Java 8] (5) 使用Lambda表达式进行设计
使用Lambda表达式进行设计 在前面的几篇文章中,我们已经见识到了Lambda表达式是怎样让代码变的更加紧凑和简洁的. 这一篇文章主要会介绍Lambda表达式怎样改变程序的设计.怎样让程序变的更加轻 ...