Get Current Time in Android: Code Example

In Android, the method to get the current time is by using the java.util.Calendar class. Here is an example code to retrieve the current time:

Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);

The above code will get the current hour, minute, and second, and then save them in variables named hour, minute, and second. You can modify the code as needed to obtain other time information such as year, month, or day.

bannerAds