Fetching today’s date in Java

Try this:

import java.util.*;
import java.text.*;
 
public class Main { 
   public static void main(String[] args) throws Exception {
      System.out.println(getDateTime("dd-MM-yyyy HH:mm:ss.SSS"));
   }
 
   public static String getDateTime(String format) {
      Calendar calendar = Calendar.getInstance();
      SimpleDateFormat dateFormat = new SimpleDateFormat(format);
      Date date = calendar.getTime();
      return dateFormat.format(calendar.getTime());
   }
}