Java Date Difference dateDiffWithNow(Calendar sDate)

Here you can find the source of dateDiffWithNow(Calendar sDate)

Description

date Diff With Now

License

Apache License

Declaration

public static long dateDiffWithNow(Calendar sDate) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static long dateDiffWithNow(Calendar sDate) {

        Date now = Calendar.getInstance().getTime();
        long timeDiff = now.getTime() - sDate.getTimeInMillis();

        return timeDiff;
    }//from  w  ww.j  a v a 2  s  . c  om

    public static long dateDiffWithNow(Date sDate) {

        Date now = Calendar.getInstance().getTime();
        long timeDiff = now.getTime() - sDate.getTime();

        return timeDiff;
    }

    public static long dateDiffWithNow(long sDate) {

        Date now = Calendar.getInstance().getTime();
        long timeDiff = now.getTime() - sDate;

        return timeDiff;
    }

    public static String getTime(Date executionTime) {
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        return formatter.format(executionTime);
    }

    public static Date getTime(String timeInString) {

        DateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");
        Date date = null;

        try {

            date = dateFormat.parse(timeInString);

            // System.out.println("Date and Time: " + date);

        } catch (Exception e) {
            e.printStackTrace();
        }

        return date;

    }
}

Related

  1. DateDiff(String strDateBegin, String strDateEnd, int iType)
  2. dateDiffer(String time1, String time2, String formatStr)
  3. dateDiffInDays(Date dateStart, Date dateEnd)
  4. dateDiffInDaysIgnoreTime(Date dateStart, Date dateEnd)
  5. dateDiffMonth(Date d1, Date d2)
  6. dayDiff(Date a, Date b)
  7. dayDiff(Date date1, Date date2)
  8. dayDiff(Date first, Date second)
  9. dayDiffByStartOfDay(Date a, Date b)