0

I have timestamps like below and need to calculate elapse time.

t1: 2014-11-07 11:22:39.854296-08
t2: 2014-11-07 11:22:52.748804-08

I use the following code but the result is not correct:

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS"); 

        String time1 = "2014-11-07 11:22:39.854296-08";
        java.util.Date parsedDate1 = dateFormat.parse(time1);

        String time2 = "2014-11-07 11:22:52.748804-08";
        java.util.Date parsedDate2 = dateFormat.parse(time2);

        int elapse = (int)(parsedDate2.getTime() - parsedDate1.getTime());

If I use format: ("yyyy-MM-dd hh:mm:ss"), the result is correct.

John
  • 193
  • 2
  • 14

0 Answers0