gpt4 book ai didi

java - 将一个日期字段分配给另一日期字段

转载 作者:行者123 更新时间:2023-12-01 18:35:00 25 4
gpt4 key购买 nike

我需要在不影响原始日期的情况下进行一些日期操作。如果我这样做:

Date tempDate = new Date();
tempDate = youthMember.getDob();
CalendarUtil.addMonthsToDate(tempDate, 96);

然后 tempDate 和 YouthMember.getDob() 都会增加 96 个月。我尝试过 setValue()、setDate() 并搜索网络。

非常感谢您的帮助。

最佳答案

您有一个日期对象指向另一个日期对象,因此它们都返回相同的值。

Date tempDate = new Date(youthMember.getDob().getTime());
CalendarUtil.addMonthsToDate(tempDate, 96);

关于java - 将一个日期字段分配给另一日期字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22391645/

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