특정 날짜와 시간으로 캘린더를 만들어야합니다.
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]));
}
날짜 문자열 형식은 DD.MM.YYYY이고 시간은 HH : MM입니다. 함수를 호출하면 "2"로그는 볼 수 있지만 "3"은 볼 수 없습니다.
왜 그런 겁니까?
a SimpleDateFormat
를 사용 하여 날짜와 시간을 구문 분석 할 수 있습니다 . 같은 것
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();
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다