package ojama;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Test {
public static void main(String[] args) throws Throwable {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
Date parse = format.parse("20180321141111");
Date date = format.parse("20180321141111");
long between = date.getTime() - parse.getTime();
long day = between / (24 * 60 * 60 * 1000);
long hour = (between / (60 * 60 * 1000) - day * 24);
long min = ((between / (60 * 1000)) - day * 24 * 60 - hour * 60);
long s = (between / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
System.out.println(day + "天" + hour + "小时" + min + "分" + s + "秒");
}
}
Java获取2个时间的时间差(精确到秒)
最新推荐文章于 2024-07-01 02:06:56 发布