Super friendly <br/>code & developer communities

Super friendly
code & developer communities

A place for coders and developers to share, learn and grow together.

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

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:-");


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

How does it work
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.

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.

P.S. If you have any questions, click here to join our community and feel free to ask any questions.