I am trying to set an alarm on a particular day and time.So setting hour and minute using Calendar
.But when i try to access the hour which is set in Calendar
using cal.set
,i get a different value than that was set by me manually.
Code
Calendar cal=Calendar.getInstance();
cal.set(Calendar.HOUR,7);
cal.set(Calendar.MINUTE,30);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Toast.makeText(getApplicationContext(), "Alarm worked. "+cal.HOUR+cal.MINUTE,cal.SECOND Toast.LENGTH_LONG).show();
Result i want
Alarm worked. 7:30:0
What i get now
Alarm worked. 10:12:13
P.S
1.I found many posts which deal with Calendar
issues but couldn't find my solution.
2.The result what i am getting i.e 10:12:13
is not my current time(current date,current minute,current second) either.So i don't know why and from where these data are coming.
3.I tried using HOUR_OF_DAY
instead of HOUR
but nothing useful.
Solution
Toast.makeText(getApplicationContext(), "Alarm worked. "+cal.get(Calendar.HOUR)+" "+cal.get(Calendar.MINUTE)+" "+cal.get(Calendar.SECOND), Toast.LENGTH_LONG).show();
This worked because Calendar.HOUR
,Calendar.MINUTE
are constants.See the answer of @PopoFibo to get the clear picture.