Skip to Content

Simple Java Calendar Example

  1. /*
  2.   Simple Java Calendar Example
  3.   This example shows how to use Java Calendar class to display current date
  4.   and time.
  5. */
  6.  
  7. import java.util.Calendar;
  8.  
  9. public class JavaSimpleCalendarExample {
  10.  
  11.   public static void main(String[] args) {
  12.    
  13.     //use getInstance() method to get object of java Calendar class
  14.     Calendar cal = Calendar.getInstance();
  15.    
  16.     //use getTime() method of Calendar class to get date and time
  17.     System.out.println("Today is : " + cal.getTime());  
  18.   }
  19. }
  20.  
  21. /*
  22. TYPICAL Output would be
  23. Today is : Sun Sep 09 20:16:35 EDT 2007
  24. */