Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
特定の文字列が特定の日付形式であるかどうかを確認したい。そうでない場合、ユーザーはエラーメッセージをスローできるはずです。
DateTimeFormat format=DateTimeFormat.getFormat("yyyy-MM-dd"); Date d= format.parse("1990-10-");
この入力では、エラーが発生するはずです。私は try と catch を試しましたが、例外はスローされません。
java.text.SimpleDateFormat を使用すると、ParseException がスローされます。
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd"); try { Date d= format.parse("1990-10-"); } catch (ParseException e) { ... }