Display Date and Time in Java

Download
Download is available until [expire_date]
  • Version
  • Download 26
  • File Size 2.54 KB
  • File Count 1
  • Create Date April 18, 2016
  • Last Updated April 18, 2016

Display Date and Time in Java

Display Date and Time in Java

Java program that will display the system date and time. You can also modify the format of the time using the SimpleDateFormat class.

The program is written in console and gui format.

Source code:

import java.util.*; 
import java.text.*; 
import javax.swing.JOptionPane;
class DisplayDate {
	
public static void main(String[] args) {
	
Date dateToday = new Date();

SimpleDateFormat format1 = new SimpleDateFormat( );
SimpleDateFormat format2 = new SimpleDateFormat ("MMMM dd, yyyy");

JOptionPane.showMessageDialog(null,"Today is " + format1.format(dateToday) + " - Short Format" + "
Today is " + format2.format(dateToday) + " - User Defined Format");

}
}
, , , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.