Java-Updating Calendar

Updating Calendar

The set( ) method is used to sets the values for the fields YEAR, MONTH, DAY_OF_MONTH, HOUR, MINUTE, and SECOND.

Program

0

Program Source

import java.util.Calendar;

public class Javaapp {

    public static void main(String[] args) {
        
        Calendar caldr = Calendar.getInstance();
        int year = 2000;
        int month = 5;
        int dayOfMonth = 6;
        int hour = 12;
        int minute = 45;
        int second = 55;
        caldr.set(year, month, dayOfMonth, hour, minute, second);
        System.out.println("YEAR         : "+caldr.get(Calendar.YEAR));
        System.out.println("MONTH        : "+caldr.get(Calendar.MONTH));
        System.out.println("DAY_OF_MONTH : "+caldr.get(Calendar.DAY_OF_MONTH)); 
        System.out.println("HOUR         : "+caldr.get(Calendar.HOUR));
        System.out.println("MINUTE       : "+caldr.get(Calendar.MINUTE));
        System.out.println("SECOND       : "+caldr.get(Calendar.SECOND)); 
    }
}

Leave a Comment