Here you can find the source of timeDifferenceWithCurrentTime(Date startTime)
Parameter | Description |
---|---|
startTime | a parameter |
public static long timeDifferenceWithCurrentTime(Date startTime)
//package com.java2s; // distribute, sublicense, and/or sell copies of the Software, and to import java.util.Calendar; import java.util.Date; public class Main { /**/*from ww w.j a v a 2 s . c om*/ * This Methods gives the result Milliseconds elapsed to Current Time * Note : this method does not check for dates. It only works on time * Example : * Input Time : 12 July 2011 12:20:80 AM * The input will be converted to current date and the time will be retained * and this newly formed date will be compared with current date's time. * @param startTime * @return */ public static long timeDifferenceWithCurrentTime(Date startTime) { Date currentTime = getCurrentDateTime(); Calendar startDateCal = Calendar.getInstance(); startDateCal.setTime(startTime); Calendar newTime = Calendar.getInstance(); newTime.set(Calendar.HOUR, startDateCal.get(Calendar.HOUR)); newTime.set(Calendar.MINUTE, startDateCal.get(Calendar.MINUTE)); newTime.set(Calendar.MILLISECOND, startDateCal.get(Calendar.MILLISECOND)); return ((newTime.getTime()).getTime() - currentTime.getTime()); } public static Date getCurrentDateTime() { Calendar cal = Calendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); } }