Java code to print current system date and time.



Program Code :




import java.util.*;

public class DateTime{

   public static void main(String args[]) {
      int day, month, year;
      int second, minute, hour;
      GregorianCalendar date = new GregorianCalendar();
      day = date.get(Calendar.DAY_OF_MONTH);
      month = date.get(Calendar.MONTH);
      year = date.get(Calendar.YEAR);
      second = date.get(Calendar.SECOND);
      minute = date.get(Calendar.MINUTE);
      hour = date.get(Calendar.HOUR);
      System.out.println("Current date >>  "+day+"/"+(month+1)+"/"+year);
      System.out.println("Current time >>  "+hour+" : "+minute+" : "+second);
   }
}


Output :

 Current date >>  3/3/2014
Current time >>  0 : 51 : 53



How to write a java program to print date and time,How to write a java program to print date and time,java program to print date and time
 
Top