Date time set in calendar is '2016-6-18 13:54:00 ' and current date time is '2016-6-18 14:45:00' i.e. 2016-6-18 2:45 PM. In the calendar I set the MONTH
value to be 5 as month is zero-based there. This is in android :
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, 2016);
calendar.set(Calendar.MONTH, 5);
calendar.set(Calendar.DATE, 18);
calendar.set(Calendar.HOUR_OF_DAY,13);
calendar.set(Calendar.MINUTE,54);
calendar.set(Calendar.SECOND,0);
long alarmTime =calendar.getTimeInMillis();
alarmTime = TimeUnit.MILLISECONDS.toSeconds(alarmTime);
long timeMillis = System.currentTimeMillis();
long currentTimeSeconds =TimeUnit.MILLISECONDS.toSeconds(timeMillis);
if (alarmTime > currentTimeSeconds) {
Toast.makeText(context, "Alarm is set", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(context, "Alarm is not set", Toast.LENGTH_SHORT).show();
}
But the result shows the toast "Alarm is set" whereas I expected the otherwise i.e. "Alarm is not set".
What is going on here ?
EDIT: To my surprise, the Genymotion emulator shows 'Alarm is set' while the real device shows 'Alarm is not set'. Why is this difference ?