I am calculating the difference between two timestamps which is in the following format
2013-07-22 05:24:24.77
I am using the following method to calculate the difference between two timestamps
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Date resDate = sdf.parse(responseData.getTimestamp().toString());
Date reqDate = sdf.parse(requestData.getTimestamp().toString());
System.out.println("response-->"+responseData.getTimestamp());
System.out.println("request-->"+requestData.getTimestamp());
System.out.println("diff-->"+(resDate.getTime()-reqDate.getTime()));
The difference between two timestamps is negative in the following cases. For example
Response date : 2013-07-22 05:24:24.77
Request date : 2013-07-22 05:24:24.663
Result is :
diff-->-586
it should subtract something like this "770-663" instead it subtracting the timestamp as "77-663".
Can anyone please suggest what changes I should make or is there any other way to do it??
Thanks in advance