The abstract Calendar class provides a set of methods that allows you to convert a time in milliseconds to a number of useful components. Some examples of the type of information that can be provided are year, month, day, hour, minute, and second. The getInstance( ) method is used to get the calender object for the default locale and time zone.



Program Source

import java.util.Calendar;

public class Javaapp {

    public static void main(String[] args) {
        Calendar caldr = Calendar.getInstance();
        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