如何获得达到某个日期的日,小时,分钟

Ahm*_*tib 2 android datepicker android-intent android-layout android-date

我需要让Day Hours Minutes达到特定日期示例:

日期="2015-08-08 16:38:28"

Current_Date = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date());
Run Code Online (Sandbox Code Playgroud)

并达到Date结果将是 2天1小时30分钟

N J*_*N J 6

我在google上进行简单搜索

    String dateStart = "01/14/2012 09:29:58";
    String dateStop = "01/15/2012 10:31:48";

    //HH converts hour in 24 hours format (0-23), day calculation
    SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

    Date d1 = null;
    Date d2 = null;

    try {
        d1 = format.parse(dateStart);
        d2 = format.parse(dateStop);

        //in milliseconds
        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(diffDays + " days, ");
        System.out.print(diffHours + " hours, ");
        System.out.print(diffMinutes + " minutes, ");
        System.out.print(diffSeconds + " seconds.");

    } catch (Exception e) {
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

见下面的链接

  1. http://www.mkyong.com/java/how-to-calculate-date-time-difference-in-java/
  2. 如何在java中找到两个日期之间的差异持续时间?
  3. 在java中计算日期/时间差异