Java program to display Date and Time using Calendar.

Simple Java Calendar Example :

This example shows how to use Java Calendar class to display current date  and time.

This Java source code to print or display date and time of current system. This program prints current date and time of current system. Java source code to print date and time is given below :-

import java.util.Calendar;
class javacalender {
public static void main(String[] args) {

//use getInstance() method to get object of java Calendar class
Calendar cal = Calendar.getInstance();

   //use getTime() method of Calendar class to get date and time
System.out.println(“Today is : ” + cal.getTime());

output would be:






In above Example we import package import java.util.Calendar class to show the calendar on prompt and also create object of the calendar class cal.

The abstract Calendar class provides a set of methods that allows you to convert a time in milliseconds to a number of useful components.Calendar provides no public constructors.Calendar defines several protected instance variables.

Related Posts

Comments are closed.