Getting the Current Time
This section shows the way of getting the current time of the system.
In this section, through the given program you can get the current time in the proper format (Hour:Minute:Second AM/PM). This program shows the current time by using the various methods of the Calendar class. These are explained as follows:
Code Description:
Calendar:
Date is the special instance of the time. This class helps you to convert a date
format object into the integer fields like YEAR, MONTH, HOUR, MINUTE, SECOND
etc.
Calendar.get(Calendar.MINUTE):
Above method gives you the minute value from the current time and MINUTE is
the predefined field of the Calendar class which returns the integer value i.e.
the minute value of the current time
Calendar.AM_PM:
Above field of the Calendar class returns the integer value 1, if the
current time is in the PM otherwise it returns 0 value which denotes the time is
in the AM period.
Here is the code of the program:
import java.util.*;
|