年月日を別途に設定しましたJComboBoxes
月JComboBoxにinteger
月の値ではなく月の名前を表示するように自分自身がrenderer
です。月がどこから始まるのか0 (0-January....11-December)
JComboBoxの年、月、日の整数値を日付型に連結または書式設定
私の問題は、年、月、日を一緒にしてDate
データ型に割り当てることです。
String
変数
int startYear = Integer.parseInt(jcmbFirstSemStartDateYear.getSelectedItem().toString());
int startMonth = Integer.parseInt(jcmbFirstSemStartDateMonth.getSelectedItem().toString());
int startDay = Integer.parseInt(jcmbFirstSemStartDateDay.getSelectedItem().toString());
String startDate = startYear+"-"+startMonth+"-"+startDay; //not sure if this okay
Date completeStartDate = java.sql.Date.valueOf(startDate);
JOptionPane.showMessageDialog(null,completeStartDate);
hasConflict(completeStartDate, completeEndDate); //method to check conflict
に一緒に年、月、日の連結を試みたが、私はcompleteStartDate
の値を印刷したとき、それは01
2月の代わりに1月と読み替えて、競合をチェックする月を抽出すると心配です。
public static boolean hasConflict(Date aStartDate, Date aEndDate){
boolean hasConflict = false;
Calendar calStart = Calendar.getInstance();
calStart.setTime(aStartDate);
int startYear = calStart.get(Calendar.YEAR);
int startMonth = calStart.get(Calendar.MONTH); //extract month
int startDay = calStart.get(Calendar.DAY_OF_MONTH);
// ... if else conditions to compare startDate with endDate
return hasConflict;
}
後で、これらの日付をmysql
データベースに保存します。
どのような考えやアドバイスですか?
ありがとうございます。
フォーマットに基づいて 'String'表現を作成して解析することもできますし、[' LocalDate.of(year、month、dayOfMonth) '](https://docs.oracle.com/javase)を使用することもできます。 /8/docs/api/java/time/LocalDate.html#of-int-int-int-) – MadProgrammer