0

为什么 getTime() 有错误?我已经尝试了一切,但无法弄清楚问题所在。据我所知,我已将 String arrayOpportunity[2] 转换为日期。(它最初是一个字符串。)谢谢!

SimpleDateFormat df = new SimpleDateFormat();
df.applyPattern("yyyy-MM-dd HH:mm:ss");

// Calendar timestamp = Calendar.getInstance();
// timestamp.setTime(df.parse(arrayOpportunity2)[0]);

arraySuspects.add(arrayGPS[0]);
// }
// long timediff = coord2.getTimestamp().getTimeInMillis() -
// coord1.getTimestamp().getTimeInMilis();

Date convertedDate = df.parse(arrayOpportunity[2]);

Date duration = df.parse("0000-00-00 00:14:59");
Date lastTime = df.parse(arrayOpportunity[2]);

// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/mm/dd");

System.out.println(arrayOpportunity[2]);

//  arrayOpportunity[2].setTime(arrayOpportunity[2].getTime() + duration);
//  lastTime += duration;
arrayOpportunity[2].setTime(arrayOpportunity[2].getTime() + (((14 * 60) + 59)* 1000));
4

1 回答 1

1

调用df.parse(arrayOpportunity[2]);不会转换arrayOpportunity[2]为 a Date,而是将该值分配给lastTime。在您的代码调用中,lastTime.getTime()而不是arrayOpportunity[2].getTime()asarrayOpportunity[2]仍然是String

// Create your date parser
SimpleDateFormat df = new SimpleDateFormat();
// Set the date pattern
df.applyPattern("yyyy-MM-dd HH:mm:ss");
// Create a Date object by parsing the value of arrayOpportunity[2]
Date lastTime = df.parse(arrayOpportunity[2]);
// Set a new value to the Date object by performing a calculation on the result of getTime()
lastTime.setTime(lastTime.getTime() + (((14 * 60) + 59)* 1000));
于 2012-10-24T15:23:08.323 回答