Javatpoint Logo

91-9990449935

 0120-4256464

Javatpoint Logo

Java Date and Time

The java.time, java.util, java.sql and java.text packages contains classes for representing date and time. Following classes are important for dealing with date in java.

Java has introduced a new Date and Time API since Java 8. The java.time package contains Java 8 Date and Time classes.

But classical or old Java Date API is also useful. Let's see the list of classical Date and Time classes.

How to get Current Date and Time

There are many ways to print current date and time in java.

1st way:

Output:

2017-01-23

2nd way:

Output:

00:01:14.341

3rd way:

Output:

2017-01-24T00:03:31.593

4th way:

Output:

2017-01-23T18:35:23.669Z

5th way:

Output:

Wed Mar 27 08:22:02 IST 2015

6th way:

Output:

Wed Mar 27 08:22:02 IST 2015

7th way:

Output:

2015-03-27

8th way:

Output:

Wed Mar 27 08:22:02 IST 2015




Latest 4 Tutorials on JavaTpoint