Android - Find out what hour of day it is
I want to use and alarmManager that sets a repeating alarm to go off on the hour, every hour. I know how to set a repeating alarm every hour but not how to actually set it from the top of the hour, I need to know this value for the 'whatTime' variable below.
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME开发者_StackOverflow, whatTime, 1*60*60*1000, operation);
Also I want to be able to set a flag that for e.g. - if the time happens to be between 4 and 8 in the daytime, perform some operations, otherwise don't bother.
So I really need to know how to find out the hour of the day, can anyone tell me how to do this? Many thanksTry:
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
- Calendar.HOUR_OF_DAY gives you the 24-hour time.
- Calendar.HOUR gives you the 12-hour time.
精彩评论