codescracker


java

Java Program to Print Date and Time



« Previous Program Next Program »


Print Date and Time

To print date and time in Java programming, you have to create and use the object of Date class. Let's see the following program to know how to print date and time in Java.

Java Programming Code to Print Current Date and Time

Following Java Program will print the current system date, day, and time on the output screen. Date will be printed in the form dd:mm:yy and day will be printed in the form Fri, and the time will be printed in the form hh:mm:ss AM/PM :

/* Java Program Example - Print Date and Time */
		
import java.util.*;
import java.text.*;

public class Test
{
   public static void main(String args[])
   {
      Date dNow = new Date( );
      
      SimpleDateFormat ft1 = new SimpleDateFormat ("dd/MM/yyyy");
      SimpleDateFormat ft2 = new SimpleDateFormat("E");
      SimpleDateFormat ft3 = new SimpleDateFormat("hh:mm:ss a");
      
      System.out.println("The Current Date is " + ft1.format(dNow));
      System.out.println("Today is " + ft2.format(dNow));
      System.out.println("The Current Time is " + ft3.format(dNow));
   }
}

When the above Java Program is compile and executed, it will produce the following output:

Java Program to print time date

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test