Java Calendar add() MethodThis method adds the specified (signed) amount of time to the given calendar field, based on the calendar's rules. SyntaxParameterfield - the calendar field. ReturnsThis method does not return a value ThrowsIllegalArgumentException - if field is ZONE_OFFSET, DST_OFFSET, or unknown, or if any calendar fields have out-of-range values in non-lenient mode. Example 1Test it NowOutput: Sun Jul 29 07:42:05 PDT 2018 Thu Jul 29 07:42:05 PDT 2027 Example 2Test it NowOutput: Sun Jul 29 07:43:38 PDT 2018 Sat Sep 29 07:43:38 PDT 2018 Example 3Test it NowOutput: Sun Jul 29 07:44:56 PDT 2018 Wed Aug 08 07:44:56 PDT 2018 Example 4Test it NowOutput: 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
Next TopicJava Calendar Class
|