使用joda-time工具类 计算时间相差多少 天,小时,分钟,秒

下面程序使用了两种方法计算两个时间相差 天,小时,分钟,秒

package jodotest;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.joda.time.DateTime;
import org.joda.time.Days;
import org.joda.time.Hours;
import org.joda.time.Interval;
import org.joda.time.Minutes;
import org.joda.time.Period;
import org.joda.time.Seconds;

/**
* @author wanggang
*
*/
public class Test {
public static void test1(Date d1, Date d2){

// 毫秒ms
long diff = d2.getTime() - d1.getTime();

long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000) % 24;
long diffDays = diff / (24 * 60 * 60 * 1000);

System.out.print("时间相差:");
System.out.print(diffDays + " 天 ");
System.out.print(diffHours + " 小时 ");
System.out.print(

上一篇:与美女CEO罗元裳共进午餐!朋友圈被7分钟理财刷屏!


下一篇:LinuxKit NanoServer和DevOps是个啥关系?