Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Calendar;

public class Main {

    public static void main(String[] args) {

        Calendar cal = Calendar.getInstance();

        // display the current date and time
        System.out.println("Current Calendar Date: " + cal.getTime());

        // use clear method to set year as undefined.
        cal.clear(Calendar.YEAR);

        // print the result
        System.out.println("The calendar shows : " + cal.getTime());

        // use clear method to set month as undefined.
        cal.clear(Calendar.MONTH);

        System.out.println("The calendar shows : " + cal.getTime());
    }
}