我需要弄清楚如何创建一个临时 Calendar 对象(已经存在的永久"日历的副本),以便我可以操作该副本:tempCal.add(单位,值).我需要保持原来的日历对象不变,所以我真的不想直接在它上面调用add(unit, value).
I need to figure out how to create a temporary Calendar object (a copy of a "permanent" calendar that already exists) so that I can manipulate the copy: tempCal.add(unit, value). I need to keep the original calendar object unchanged, so I really don't want to call add(unit, value) on it directly.
由于我创建副本的任何尝试都没有真正奏效,我目前的丑陋技巧是调用 permanentCal.add(unit, value),显示所需的结果,然后调用 permanentCal.add (unit, -value)——这看起来很不酷.
Since none of my attempts at creating a copy actually worked, my current ugly hack is to call permanentCal.add(unit, value), display the desired results, then call permanentCal.add (unit, -value) — which just seems, uncool.
java.util.Calendar 有一个 clone 方法,你可以使用它.里面的所有数据都是由原语组成的,所以你不会遇到麻烦.
java.util.Calendar has a clone method, you could use that. All data in it is made of primitives, so you will not run into troubles.
看看这些答案:
这篇关于在 Java 中创建日历对象的临时副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
解析 ISO 8601 字符串本地日期时间,就像在 UTC 中Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期时间,就像在 UTC 中一样)
如何将公历字符串转换为公历?How to convert Gregorian string to Gregorian Calendar?(如何将公历字符串转换为公历?)
Java:GregorianCalendar 的最大值和最小值是什么/在哪Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
1582 年 10 月 15 日之前日期的日历到日期转换.公历Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日历到日期转换
java日历setFirstDayOfWeek不起作用java Calendar setFirstDayOfWeek not working(java日历setFirstDayOfWeek不起作用)
Java:获取当前星期几的值Java: getting current Day of the Week value(Java:获取当前星期几的值)