Current Date & Time in JAVA programming


  1. import java.util.Calendar;
  2.  
  3. import java.util.GregorianCalendar;
  4.  
  5. import org.omg.CORBA.Current;
  6.  
  7. public class TimeandDate {
  8.  
  9.     public static void main(String[] args) {
  10.  
  11.         GregorianCalendar date=new GregorianCalendar();
  12.  
  13.         int day,month,year;
  14.  
  15.         int hour,minute,second;
  16.  
  17.         day=date.get(Calendar.DAY_OF_MONTH);
  18.  
  19.         month=date.get(Calendar.MONTH);
  20.  
  21.         year=date.get(Calendar.YEAR);
  22.  
  23.         hour=date.get(Calendar.HOUR_OF_DAY);
  24.  
  25.         minute=date.get(Calendar.MINUTE);
  26.  
  27.         second=date.get(Calendar.SECOND);
  28.         System.out.println("Current Time is : "+hour+":"+minute+":"+second+"\n");
  29.  
  30.         System.out.println("Current Date is : "+day+"/"+(month+1)+"/"+year+"\n");
  31.  
  32.     }
  33. }
  34.  

No comments:

Post a Comment