ユーザーが分を入力し、プログラムが現在の日付と時刻+ユーザーが入力した分を表示する小さなプログラムを作成しました。
final String DATE_FORMAT_NOW = "MM/dd/yyyy HH:mm:ss";
final DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss", Locale.US);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, Integer.valueOf(sample.getMinutes()));
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
String dt = sdf.format(cal.getTime());
System.out.println(" Date and time with added Minutes : " + (dateFormat.parse(dt));
サンプル
private String minutes;
//getter and setter
この例外が発生します
java.lang.NumberFormatException:入力文字列の場合: ""
私がここで間違っていることは何ですか?使用する必要があります
Integer.parseInt
また
Integer.valueOf(Integer.parseInt(sample.getMinutes())));?