Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the calendar in android for particular hour

Tags:

java

android

I dont want to add the year or month.Just the hour , minutes and seconds for each day. How to use it the Calendar object to do it ? This is my code

// get a Calendar object with current time Calendar cal = Calendar.getInstance(); // add 5 minutes to the calendar object  cal.add(Calendar.HOUR, 4); cal.add(Calendar.MINUTE, 40);     Intent i = new Intent(this, Receiver.class); i.putExtra("alarm_message", "O'Doyle Rules!"); // In reality, you would want to have a static variable for the request code instead of 192837 PendingIntent sender = PendingIntent.getBroadcast(this, 192837, i, PendingIntent.FLAG_UPDATE_CURRENT);  // Get the AlarmManager service AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender); 
like image 415
Chetan Avatar asked Apr 24 '11 11:04

Chetan


2 Answers

try using

calendar.set(Calendar.HOUR_OF_DAY, 4); calendar.set(Calendar.MINUTE, 40); calendar.set(Calendar.SECOND, 0); 
like image 76
nadav Avatar answered Oct 02 '22 22:10

nadav


try this too

cal.set(2013,2,7,15,42,30); 

Note: Months value is MonthNumber-1 (Jan is 0, Feb is 1 and so on).

like image 39
Saif Hamed Avatar answered Oct 02 '22 20:10

Saif Hamed