gpt4 book ai didi

java - 无法添加时间戳

转载 作者:行者123 更新时间:2023-12-01 15:05:14 25 4
gpt4 key购买 nike

为什么 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));

最佳答案

调用df.parse(arrayOpportunity[2]);不转换arrayOpportunity[2]Date ,它将该值分配给 lastTime 。在您的代码中调用 lastTime.getTime()而不是arrayOpportunity[2].getTime()arrayOpportunity[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));

关于java - 无法添加时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13052176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com