Java Calendar add() Method

This method adds the specified (signed) amount of time to the given calendar field, based on the calendar's rules.

Syntax

Parameter

field - the calendar field.

amount - the amount of date or time to be added to the field.

Returns

This method does not return a value

Throws

IllegalArgumentException - if field is ZONE_OFFSET, DST_OFFSET, or unknown, or if any calendar fields have out-of-range values in non-lenient mode.

Example 1

Output:

Sun Jul 29 07:42:05 PDT 2018
Thu Jul 29 07:42:05 PDT 2027

Example 2

Output:

Sun Jul 29 07:43:38 PDT 2018
Sat Sep 29 07:43:38 PDT 2018

Example 3

Output:

Sun Jul 29 07:44:56 PDT 2018
Wed Aug 08 07:44:56 PDT 2018

Example 4

Output:

Sun Jul 29 07:46:00 PDT 2018
Sun Jul 29 17:46:00 PDT 2018
Sun Jul 29 17:56:00 PDT 2018
Sun Jul 29 17:56:10 PDT 2018