source fie name: datedemo2.java 

import java.util.*;

class datedemo2

{

public static void main(String as[])

{

System.out.println("Date and Time demo program: ");


Date d=new Date();

System.out.println("Today's Date and Time is: "+d);

int day=d.getDay();

int mon=d.getMonth();

int year=d.getYear();

System.out.println("Today's Date: "+day+"-"+mon+"-"+year);


int hrs=d.getHours();

int min=d.getMinutes();

int sec=d.getSeconds();

System.out.println("Current Time is : "+hrs+":"+min+":"+sec);


}

}

output:
D:\JavaPrograms\Misc>javac datedemo2.java

D:\JavaPrograms\Misc>java datedemo2
Date and Time demo program:
Today's Date and Time is: Fri Jun 04 11:49:00 IST 2021
Today's Date: 5-5-121
Current Time is : 11:49:0