Java Program to display current date and time


This Java example will show you how to display current date and time using Formatter and Calender class.

package javaapplication1;

import java.util.Calendar;
import java.util.Formatter;

/**
 *
 * @author User
 */
public class JavaCurrentDateTime {
    public static void main(String args[]) {
      Formatter fmt = new Formatter();
      Calendar cal = Calendar.getInstance();
      fmt = new Formatter();
      fmt.format("%tc", cal);
      System.out.println(fmt);
   }
}

 

Output: Mon May 03 10:36:46 IST 2021

 

We can also print the current date and time by using the date class

 

package javaapplication1;

import java.util.Date;

/**
 *
 * @author User
 */
public class JavaCurrentDateTime {
public static void main(String args[]) {
Date d = new Date();
System.out.println(d.toString());
}
}

 

Output: Mon May 03 10:38:36 IST 2021


Subscribe For Daily Updates

JAVA File IO examples

JAVA Date & Time Progamming Examples

JAVA Collections

Flutter Questions
Android Questions