DEV Community

khanshahabdin
khanshahabdin

Posted on

Answer: How to get current hour in android?

We can use the Calendar class to get a format like "HH:mm:ss"

Calendar calendar = Calendar.getInstance();
int hour24hrs = calendar.get(Calendar.HOUR_OF_DAY); 
int hour12hrs = calendar.get(Calendar.HOUR); 
int minutes = calendar.get(Calendar.MINUTE); 
int seconds = calendar.get(Calendar.SECOND); 
System.out.println("Current hour 24hrs format:  " + hour24hrs + ":" + minutes +":"+ seconds);
System.out.println("Current hour 12hrs format:  "

Top comments (0)