如何用java在两个不同的时间之间求和。例如,我有这个:
t1 = 10:03:45
t2 = 03:00
t3 = 01:12
==> Sum= 10:07:57
这是我的代码文章;
SimpleDateFormat formatter = new SimpleDateFormat("mm:ss");
SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss");
Time t1 = new Time(formatter.parse("10:03:45").getTime());
Time t2 = new Time(formatter.parse("03:00").getTime());
Time t3 = new Time(formatter.parse("01:12").getTime());
Long sum= formatter2.parse(t1.toString()).getTime() +(formatter.parse(t2.toString()).getTime() + formatter.parse(t3.toString()).getTime());
System.out.println("***** gettime t1 "+formatter2.parse(t1.toString()).getTime()); // -2997000
System.out.println("******* gettime t2 "+formatter.parse(t2.toString()).getTime()); // -3597000
System.out.println("******* gettime t3 "+formatter.parse(t3.toString()).getTime()); // -3599000
System.out.println("-----------Sum with time "+formatter2.format(total)); // 22:10:07
System.out.println("-----------Sum "+sum); //-10193000
我不明白为什么它显示时间的否定,而且总数不正确。
感谢您帮助我找到“时代”的确切总数,