Adding time issue using Date's getTime method
The following code is incorrectly adding 5 hours to the resultant time.
I need to be able to add dates, and this just isn't working right.
Is this a bug or am I missing something?
long msecSum = 0 ;
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS") ;
try
{
Date date1 = dateFormat.parse("01:02:05.101") ;
Date date2 = dateFormat.parse("02:03:10.102") ;
System.out.println("Date1: " + dateFormat.format(date1));
System.out.println("Date2: " + dateFormat.format(date2));
msecSum = date1.getTime() + date2.getTime() ; // adds 5 hours !!!
System.out.println("Sum: " + dateFormat.format(msecSum)) ;
}
catch (Exception e)
{
System.out.println("Unable to process time values");
}
Results:
Date1: 01:02:05.101
Date2: 02:03:10.102
Sum: 08:05:15.203 // should be 3 hours, not 8

