Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current hours in 24 hrs format in Android?

I am having some trouble using the calendar class in android. How can I get the current time in 24 format?

like image 720
Adham Avatar asked Dec 27 '11 20:12

Adham


2 Answers

Calendar c1 = Calendar.getInstance();

if You want 12 Hour Format Use - c1.set(Calendar.HOUR, new Date().getHours());

if You want 24 Hour Format Use - c1.set(Calendar.HOUR_OF_DAY, new Date().getHours());

like image 169
sushant gosavi Avatar answered Oct 15 '22 11:10

sushant gosavi


Use Calendar.HOUR_OF_DAY for getting hour in 24 format

Calendar rightNow = Calendar.getInstance();
int currentHour = rightNow.get(Calendar.HOUR_OF_DAY);
like image 41
Linh Avatar answered Oct 15 '22 12:10

Linh