0

I need to create a Calendar with a specific date and time.

private void setNotification(String date, String time) {
    Log.i("log", "1");
    //Get date & time
    String[] dateArr = date.split(".");
    String[] timeArr = date.split(":");
    Log.i("log", "2");
    //Set calender to lesson's date & time
    Calendar cal = Calendar.getInstance();
    cal.set(Integer.valueOf(dateArr[2]), Integer.valueOf(dateArr[1]) - 1, Integer.valueOf(dateArr[0]), Integer.valueOf(timeArr[0]), Integer.valueOf(timeArr[1]));
    Log.i("log", "3");

    //Schedule notification
    scheduleNotification(CreateNewLesson.this, cal.getTimeInMillis() - Calendar.getInstance().getTimeInMillis(), Integer.valueOf(dateArr[0] + dateArr[1] + dateArr[2] + timeArr[0] + timeArr[1]));
}

The date String format is DD.MM.YYYY and the time is HH:MM, when I call the function I can see the "2" log but not the "3".

why is that?

OmerN
  • 933
  • 2
  • 9
  • 20
  • We can only speculate why you observe the behavior you do, because the code you've presented is incomplete, and you have not included any actual sample input. If you want an answer to the question you have posed then present a [mcve]. – John Bollinger Apr 29 '16 at 16:43
  • Use the correct tool for the task, don't parse dates yourself. – Tunaki Apr 29 '16 at 16:45

1 Answers1

0

You could use a SimpleDateFormat to parse your date and time. Something like

DateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm");
Calendar cal = Calendar.getInstance();
try {
    cal.setTime(sdf.parse(String.format("%s %s", date, time)));
    // use cal....
} catch (ParseException e) {
    e.printStackTrace();
}
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249