Java Programming | Getting The Date & Time – Tutorial & Example

Introduction.

This is a tutorial for getting the date and time and displaying it or working on it. This is very useful tutorial. So Lets Learn it…

Program for Getting the date & time in java.

//import Date as we require it.
import java.util.Date;
 
// the name of our class its public
public class DateExample {
    //void main
        public static void main (String[] args)
        {
            //declare Date
            Date d = new Date();
            //print the Date
            System.out.println("Its Now:-");
            System.out.println(d.toString());
        }
}

Output

Its Now:-
Tue Nov 19 18:28:52 IST 2013

How does it work

  1. Nothing to input the date and time is directly printed.

Extending it

The program can be extended. This is a basic concept of java programming and has lots of applications.

Explanation.

  1. Import the Date.
  2. Declare the class as public
  3. Add the void main function
  4. Declare Date object.
  5. Add system.out.println() function to print the date and time.

At the end.

You learnt creating the Java program for Getting  Date and Time. So now enjoy the program.

Please comment on the post and share it.

Join India's Largest Code Learning Community on Uphub.io Get it on Google Play
Sharing options: