Samuel Knox
Samuel Knox

Reputation: 71

Cannot add Timestamps

Why is getTime() having an error? I have tried everything, but cannot figure out what the problem is. As far as I know, I have converted the String arrayOpportunity[2] into a date. (It was originally a String.) Thanks!

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));

Upvotes: 0

Views: 129

Answers (1)

doublesharp
doublesharp

Reputation: 27609

Calling df.parse(arrayOpportunity[2]); does not convert arrayOpportunity[2] to a Date, it assigns that value to lastTime. In your code call lastTime.getTime() instead of arrayOpportunity[2].getTime() as arrayOpportunity[2] is still a 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));

Upvotes: 1

Related Questions