FUNCTIONS

8. Write a Java method to display the current date and time.

            class MyDateClass{
                java.util.Date obj = new java.util.Date();
                static void printDateAndTime(){
                    java.util.Date obj = new java.util.Date();
                    System.out.println("Date : "+obj.getDate()+"/"+obj.getMonth()+"/"+(obj.getYear()+1900));
                    System.out.println("Time : "+obj.getHours()+"H:"+obj.getMinutes()+"M:"+obj.getSeconds()+"S");
                }
                public static void main(String args[]){
                    printDateAndTime();
                }
            
            }
        

OUTPUT

            Date : 15/9/2024
            Time : 20H:18M:40S