【初心者】Java質問・相談スレッド111【大歓迎】at TECH
【初心者】Java質問・相談スレッド111【大歓迎】 - 暇つぶし2ch487:デフォルトの名無しさん
08/01/28 14:32:24
>>477
文字列の取得自体はできるみたいなので、続きだけやるとこんな感じか?

//文字列をCalendarに変換
String now, birth; //"1 28 2008" と "2 17 1980" を入力させる。
DateFormat df = new SimpleDateFormat("M d yyyy");
Calendar today = Calendar.getInstance(); today.setTime(df.parse(now));
Calendar birthday = Calendar.getInstance(); birthday.setTime(df.parse(birth));

//Calendarから年齢計算
int age = today.get(Calendar.YEAR) - birthday.get(Calendar.YEAR);
birthday.set(Calendar.YEAR, today.get(Calendar.YEAR));
if (today.before(birthday)) age--;


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch