0
我正在使用數組列表來存儲過去5周的時間戳列表。時間戳列表覆蓋之前的時間戳
i.e., if today is 2014-06-09, I want to store
2014-06-02
2014-05-26
2014-05-19
2014-05-12
2014-05-05
這是我的代碼。
public class Test {
public static void main(String ap[]) throws InterruptedException{
List<Timestamp> ts = new ArrayList<Timestamp>();
Timestamp t = new Timestamp(new java.util.Date().getTime());
Timestamp temp = null;
for(int i=0;i<5;i++){
t.setTime(t.getTime()-(7*24 * (long)60* (long)60) * (long)1000);
temp = t;
System.out.println(t);
ts.add(temp);
temp = null;
}
}
}
但問題始終是我得到overrided值即列表,列表中包含的所有元素在去年timestampI即2014年5月5日) 任何人能回答這個問題?