Java Program to Find Current Date and Time

We can find the current date and time in Java in two different ways. The primary route is to utilize Date class and the second path is to utilize Calendar class. Beneath I have shared Java program to find current date and time.

First I am defining the date and time position using DateFormat and SimpleDateFormat class and afterwards I am using organization() and getTime() strategy to get current date and time.

The program is self explainable yet at the same time in the event that you are getting any trouble, at that point, you ask in remark segment.

Program

import java.util.*;
import java.text.*;
 
class DateTimeExample {
   public static void main(String...s) {
       DateFormat dateFormate = new SimpleDateFormat("dd-mm-yy hh:mm:ss");
       Date date = new Date();
       System.out.println(dateFormate.format(date));
 
       Calendar cal = Calendar.getInstance();
       System.out.println(dateFormate.format(cal.getTime()));
    }
}

Output

Java Program to Find Current Date and Time

Leave a Comment

error: Alert: Content is protected!!