我正在使用以下代码作为日期时间,但是当我的 startTime="12:00 Pm" 我的 eventDate 移动下一个日期以及系统时间为下午 12:00 时,我的日期也移动到下一个日期。
帮我看看这段代码有什么问题。
Date appt = new Date();
Calendar apptDate = new GregorianCalendar();
apptDate.setTime(appt);
String startTime = "11:00 Pm";
String[] appointmentHourMinute = startTime.split(":");
String hour = appointmentHourMinute[0];
String[] minuteAmPm = appointmentHourMinute[1].split(" ");
String minute = minuteAmPm[0];
String amPm = minuteAmPm[1];
int hourInt = Integer.parseInt(hour);
int minInt = Integer.parseInt(minute);
Calendar eventDate = new GregorianCalendar();
eventDate.set(Calendar.MONTH, apptDate.get(Calendar.MONTH));
System.out.println("Display Month"+ apptDate.get(Calendar.MONTH));
eventDate.set(Calendar.DATE, apptDate.get(Calendar.DATE));
System.out.println("Display Month"+ apptDate.get(Calendar.DATE));
eventDate.set(Calendar.YEAR, apptDate.get(Calendar.YEAR));
System.out.println("Display Month"+ apptDate.get(Calendar.YEAR));
eventDate.set(Calendar.HOUR, hourInt);
eventDate.set(Calendar.MINUTE, minInt);
eventDate.set(Calendar.SECOND, 0);
if (amPm.equalsIgnoreCase("AM")){
if(hourInt==12)
eventDate.set(Calendar.AM_PM,Calendar.PM);
else
eventDate.set(Calendar.AM_PM,Calendar.AM);
}else{
if(hourInt==12)
eventDate.set(Calendar.AM_PM,Calendar.AM);
else
eventDate.set(Calendar.AM_PM,Calendar.PM);
}