How to use Java Calendar class to display current date and time. - Java Date Time

Java examples for Date Time:Calendar

Description

How to use Java Calendar class to display current date and time.

Demo Code


import java.util.Calendar;
 
public class Main {
 
  public static void main(String[] args) {
    //use getInstance() method to get object of java Calendar class
    Calendar cal = Calendar.getInstance();
   // ww  w  . j  a va2 s. c  o  m
    //use getTime() method of Calendar class to get date and time
    System.out.println("Today is : " + cal.getTime());  
  }
}

Result


Related Tutorials