Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR,Integer.parseInt(YYYY));
cal.set(Calendar.MONTH, Integer.parseInt(MM));
cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(DD));
cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hh));
cal.set(Calendar.MINUTE, Integer.parseInt(mm));
cal.set(Calendar.SECOND,00);
SimpleDateFormat simpledateformat = new SimpleDateFormat("dd-MM-yyyy hh:mm");
EditText check = (EditText) findViewById(R.id.check);
check.setText(simpledateformat.format(cal.getTime()));
This is how I am setting time for AlarmManager
to send intent on 28-11-2018 at 2:56 PM but it sends the intent as soon as I click the send Button.
Intent code
Intent sendIntent = getPackageManager().getLaunchIntentForPackage("com.whatsapp");
try {
PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this,0,sendIntent,PendingIntent.FLAG_ONE_SHOT);
((AlarmManager) getSystemService(ALARM_SERVICE)).setExact(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(),pendingIntent);
}
catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this,"Please Install Whatsapp Messenger", Toast.LENGTH_LONG).show();
}
Time Zone is UTC+5:30.
Am I setting time in the past and how to correct it?
EDIT: I used an edittext to display the time and 29-11-2018 becomes 15-06-0211.How?
EDIT:Maybe this is wrong.
EditText date = (EditText) findViewById(R.id.date);
String dd = date.getText().toString();
char c[] = dd.toCharArray();
String YYYY = c[6]+c[7]+c[8]+c[9]+"";
String MM = c[3]+c[4]+"";
String DD =c[0]+c[1]+"";
Answer - use substring method.But I want to know why above method is wrong?