我对一年中的正确星期有疑问。我有 JTextField,我在其中以 DD.MM.YYYY 格式输入日期。
private void buttonAddCulturalActionActionPerformed(java.awt.event.ActionEvent evt) {
String date = textfieldDateOfEvent.getText();
if (!isCorrectFormatDate(date)) {
textareaExtract.append("Wrong date format!\n");
return;
}
int day = Integer.parseInt(date.substring(0, 2));
int month = Integer.parseInt(date.substring(3, 5));
int year = Integer.parseInt(date.substring(6, 10));
GregorianCalendar enteredDate = new GregorianCalendar(year, month, day);
String actionName = textfieldActionName.getText();
String placeActionName = textfieldPlaceActionName.getText();
int startHourAction = Integer.parseInt(textfieldStartHourAction.getText());
if (isAllEntered(actionName, enteredDate, placeActionName, startHourAction)) {
CulturalAction newAction = new CulturalAction(actionName, enteredDate,
placeActionName, startHourAction);
// culturalActions is priority queue
culturalActions.add(newAction);
extractAction(newAction);
} else {
textareaExtract.append("You need entered all parameters!\n");
}
}
在这里,我设置了文化行为(在构造函数中):
public CulturalAction(String nameAction, GregorianCalendar dateAction, String placeAction, int startHourAction) {
this.nameAction = nameAction;
this.placeAction = placeAction;
this.startHourAction = startHourAction;
// I have private attribute numberOfWeek in class CulturalAction
cisloTydne = dateAction.get(GregorianCalendar.WEEK_OF_YEAR);
}
当我输入日期 10.10.2013 时,它会返回第 45 周,但 40 是正确的。我来自捷克共和国。
谢谢你的建议!