In this tutorial we will learn how to display date and time using the Using Date() class. We will make the object of the date class call the toString() function it will return current date and time.


Example:

import java.util.Date;
public class JavaApplication {
    public static void main(String[] args) {

        Date objDate = new Date();
        // Display the Date & Time using toString()
        System.out.println(objDate.toString());
    }

}


Output:

Tue Apr 20 17:56:51 IST 2021

Thanks, May this example will help you.