Saturday, 31 January 2015

How To Read Current Time In JAVA

In this program we will learn how to show current time or system time in java


import java.util.*;

public class GetSystemDateAndTime
{
   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 and time is  "+day+"/"+(month+1)+"/"+year+"::"+hour+" : "+minute+" : "+second);
   }
}



Now you will get current time of your system and you can customize it as your need.




No comments:

Post a Comment