Dela via


Duration.AddTo Method

Definition

Overloads

AddTo(Calendar)

Adds this duration to a Calendar object.

AddTo(Date)

Adds this duration to a Date object.

AddTo(Calendar)

Adds this duration to a Calendar object.

[Android.Runtime.Register("addTo", "(Ljava/util/Calendar;)V", "GetAddTo_Ljava_util_Calendar_Handler")]
public abstract void AddTo (Java.Util.Calendar? calendar);
[<Android.Runtime.Register("addTo", "(Ljava/util/Calendar;)V", "GetAddTo_Ljava_util_Calendar_Handler")>]
abstract member AddTo : Java.Util.Calendar -> unit

Parameters

calendar
Calendar

A calendar object whose value will be modified.

Attributes

Exceptions

if the calendar parameter is null.

Remarks

Adds this duration to a Calendar object.

Calls java.util.Calendar#add(int,int) in the order of YEARS, MONTHS, DAYS, HOURS, MINUTES, SECONDS, and MILLISECONDS if those fields are present. Because the Calendar class uses int to hold values, there are cases where this method won't work correctly (for example if values of fields exceed the range of int.)

Also, since this duration class is a Gregorian duration, this method will not work correctly if the given Calendar object is based on some other calendar systems.

Any fractional parts of this Duration object beyond milliseconds will be simply ignored. For example, if this duration is "P1.23456S", then 1 is added to SECONDS, 234 is added to MILLISECONDS, and the rest will be unused.

Note that because Calendar#add(int, int) is using int, Duration with values beyond the range of int in its fields will cause overflow/underflow to the given Calendar. XMLGregorianCalendar#add(Duration) provides the same basic operation as this method while avoiding the overflow/underflow issues.

Java documentation for javax.xml.datatype.Duration.addTo(java.util.Calendar).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

AddTo(Date)

Adds this duration to a Date object.

[Android.Runtime.Register("addTo", "(Ljava/util/Date;)V", "GetAddTo_Ljava_util_Date_Handler")]
public virtual void AddTo (Java.Util.Date? date);
[<Android.Runtime.Register("addTo", "(Ljava/util/Date;)V", "GetAddTo_Ljava_util_Date_Handler")>]
abstract member AddTo : Java.Util.Date -> unit
override this.AddTo : Java.Util.Date -> unit

Parameters

date
Date

A date object whose value will be modified.

Attributes

Exceptions

if the date parameter is null.

Remarks

Adds this duration to a Date object.

The given date is first converted into a java.util.GregorianCalendar, then the duration is added exactly like the #addTo(Calendar) method.

The updated time instant is then converted back into a Date object and used to update the given Date object.

This somewhat redundant computation is necessary to unambiguously determine the duration of months and years.

Java documentation for javax.xml.datatype.Duration.addTo(java.util.Date).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to