I don't think your call to the Date constructor is doing what you think it is.
The three arg constructor for date is:
Date(int year, int month, int date)
Deprecated. As of JDK version 1.1, replaced by Calendar.set(year + 1900, month, date) or GregorianCalendar(year + 1900, month, date).
Try this one:
Date(int year, int month, int date, int hrs, int min, int sec)
Deprecated. As of JDK version 1.1, replaced by Calendar.set(year + 1900, month, date, hrs, min, sec) or GregorianCalendar(year + 1900, month, date, hrs, min, sec)
If all you care about is the time elapsed, then plugin the same date for both, then subtract.
try this:
Date d1 = new Date( 15, 10, 44);
System.out.println(d1.toString());
see what date is puts out.
- If this is homework, an instructor will probably frown upon the use of any of the date/time API classes methods.
import java.util.Date;
public class SomeOnesHomeWork {
public final int secondsInMinute = 60;
public final int millisecondsPerSecond =1000;
public final int milliPerMinute = secondsInMinute * millisecondsPerSecond;
public int convertMillisecondsToMinutes(long milliseconds){
return (int) (milliseconds / milliPerMinute);
}
public int differenceInMinutes(long beginTime,long endTime){
return convertMillisecondsToMinutes(endTime - beginTime);
}
public static void main(String[] argc){
//Make the dates
Date d1 = new Date(1999,12,31,23,45,44);
Date d2 = new Date(1999,12,31,23,59,59);
//We Could use Static methods, probably should
SomeOnesHomeWork aHomeWorkObject = new SomeOnesHomeWork();
System.out.println("The time between two dates in minutes: "
+ aHomeWorkObject.differenceInMinutes(
d1.getTime(),d2.getTime()));
}
}