次のように私は方法があります:同じ日内の時間間隔の適切な検証
public void storeAppointment(int year,
int monthOfYear,
int dayOfMonth,
int hourOfDayFrom,
int minuteFrom,
int hourOfDayUntil, int minuteUntil) {
Calendar appointmentCalendar = Calendar.getInstance();
appointmentCalendar.set(year, monthOfYear, dayOfMonth);
TimeZone tz = appointmentCalendar.getTimeZone();
DateTimeZone jodaTz = DateTimeZone.forID(tz.getID());
DateTime appointmentDateTime = new DateTime(appointmentCalendar.getTimeInMillis(), jodaTz);
LocalDate localDate = appointmentDateTime.toLocalDate();
// At this point I have the appointment date.
// Should e.g. throw an exception for invalid time interval
validate(hourOfDayFrom, minuteFrom, hourOfDayUntil, minuteUntil);
// set proper times for calendar
appointmentCalendar.set(Calendar.HOUR, hourOfDay);
appointmentCalendar.set(Calendar.MINUTE, minute);
// store date and times
// Should I update the localDate instead of the appointmentCalendar?
}
質問:
私は時間/分を検証する必要がありますどのように?実際の日付を含めるべきか、それとも関連しないのか?
appointmentCalendar
の代わりにlocalDate
を更新する必要がありますか?
本当に役に立ちました! Calendar.getInstance()。getTimeZone()を使ってジェネリックにしようとしたときに、特定のタイムゾーンをハードコーディングしています。これを置き換えてカレンダーを完全に削除するにはどうすればよいですか? – Jim
@Jim既定のタイムゾーンについては、前のセクションを参照してください。 –