Java Date Difference diffDateSec(java.util.Date date, java.util.Date date1)

Here you can find the source of diffDateSec(java.util.Date date, java.util.Date date1)

Description

diff Date Sec

License

Open Source License

Declaration

public static long diffDateSec(java.util.Date date, java.util.Date date1) 

Method Source Code

//package com.java2s;

import java.util.concurrent.TimeUnit;

public class Main {
    public static long diffDateSec(java.util.Date date, java.util.Date date1) {
        long t1 = date1.getTime();
        long t2 = date.getTime();

        long millis = t2 - t1;
        long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);

        return seconds;

    }// w  w  w.j a  v  a  2s. c om

    public static String getTime(java.util.Date date) {
        return format(date, "HH:mm:ss");

    }

    public static String format(java.util.Date date, String format) {
        String result = "";

        try {
            if (date != null) {
                java.text.DateFormat df = new java.text.SimpleDateFormat(format);

                result = df.format(date);

            }
        } catch (Exception e) {
        }
        return result;

    }

    public static String format(java.util.Date date) {
        if (date == null) {
            return "";
        }
        return format(date, "yyyy/MM/dd");

    }
}

Related

  1. diffDate(Date date, Date date1)
  2. diffDate(java.util.Date date, java.util.Date date1)
  3. diffDateD(Date sd, Date ed)
  4. diffDateM(Date sd, Date ed)
  5. diffDates(long starttime, long endtime, int type)
  6. diffDay(Date date1, Date date2)
  7. diffDay(Date start, Date end)
  8. diffDay(Date startDate, Date endDate)
  9. differDays(Date src, Date target)