Java Calendar set() Method

3 Nov 2024 | 2 min read

The set() method of Calendar class is used to set the specified calendar field by the specified value.

Syntax

This method is overloaded in the following ways.

Parameter

field - the calendar field.

Value ? this passed value is set to specified calendar field as the parameter.

Returns

NA

Throws

NA

Example 1

Output:

Today :Tue Aug 14 17:53:46 PDT 2018 Year :2018 Month :7 Day :3 Now Today :Sun Jun 23 10:15:20 PDT 1996 Now Year :1996 Now Month :5 Now Day :1 

Example 2

Output:

Today :Tue Aug 14 17:58:18 PDT 2018 Altered Date(1) :Wed Aug 14 17:58:18 PDT 1996 Altered Date (2) :Wed Oct 23 17:58:18 PDT 1996