Java #14: How To Print The Date and Time

————-full source code————–
//Programmer:Akinwale Owi
//Program Purpose: How to Print the Current Date & Time

package dagba.computer.samples;

/**
*
* @author Akin
*/

//array imports
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class DagbaComputerSamples
{

/**
* @param args the command line arguments
*/

public static void main(String[] args)
{ //Creating the variable that will hold my Date~ Month, Day, Year
DateFormat monthDayYear = new SimpleDateFormat(“MM/dd/yy”);

//Creating the Hours Months Seconds
DateFormat hoursMinutesSeconds = new SimpleDateFormat(“HH:mm:ss”);

//Constructor brings in the current date.
Date dateobj = new Date();

//prints out the date and time created above
System.out.println(“Today’s calendar date = ” +monthDayYear.format(dateobj));

//prints out the time
System.out.println(“The current time is = ” +hoursMinutesSeconds.format(dateobj));

}//End of Main
}//end of Class

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: