我有一个ArrayList
包括多个时间戳,目的是找到第一个和最后一个元素的差异ArrayList
.
String a = ArrayList.get(0);
String b = ArrayList.get(ArrayList.size()-1);
long diff = b.getTime() - a.getTime();
我还将类型转换为 int 但仍然给我一个错误The method getTime is undefined for the type String
.
附加信息 :
我有一个 A 类,其中包括
String timeStamp = new SimpleDateFormat("ss S").format(new Date());
有一个类 B 有一个方法private void dialogDuration(String timeStamp)
and dialogueDuration
方法包括:
String a = timeSt.get(0); // timeSt is an ArrayList which includes all the timeStamps
String b = timeSt.get(timeSt.size()-1); // This method aims finding the difference of the first and the last elements(timestamps) of the ArrayList (in seconds)
long i = Long.parseLong(a);
long j = Long.parseLong(b);
long diff = j.getTime()- i.getTime();
System.out.println("a: " +i);
System.out.println("b: " +j);
一个条件是声明(String timeStamp = new SimpleDateFormat("ss S").format(new Date());
) 在类 A 中不会被更改。并且在类 A 中创建了类 B 的对象,以便它调用dialogueDuration(timeStamp)
方法并将时间戳值传递给 B 类。
我的问题是这个减法不起作用,它给出了一个错误cannot invoke getTime() method on the primitive type long
。对于 int 和 String 类型它也会给出同样类型的错误?
预先非常感谢!