How to get the current date and time in Java Date() and Calendar()
Example Program:
Example Program:
public final class Test {
 
 //static String[] strArray = new String[10];
 //static String[] strArray1 = new String[10];
    public static void main(String args[])
    {
       DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
       //get current date time with Date()
       Date date = new Date();
       System.out.println(dateFormat.format(date));
  
       //get current date time with Calendar()
       Calendar cal = Calendar.getInstance();
       System.out.println(dateFormat.format(cal.getTime()));
    }
  
}
No comments:
Post a Comment