ava*_*gne 0 java gregorian-calendar
我有正确的一周的问题.我有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");
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,我设置了文化操作(在构造函数中):
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);
}
Run Code Online (Sandbox Code Playgroud)
当我输入日期10.10.2013并且它将返回45号周,但40正确.我来自捷克共和国.
谢谢你的建议!
Jon*_*eet 11
这就是问题:
GregorianCalendar enteredDate = new GregorianCalendar(year, month, day);
Run Code Online (Sandbox Code Playgroud)
这将是呼唤new GregorianCalendar(2013, 10, 10)- 这意味着11月,而不是10月.
month- 用于在日历中设置MONTH日历字段的值.月值基于0.例如,1月份为0.
另外两点建议:
SimpleDateFormat来执行解析,而不是自己执行| 归档时间: |
|
| 查看次数: |
649 次 |
| 最近记录: |