LoginSignup
0
0

Javaで誕生日から年齢を求める方法

Posted at

背景

誕生日と年齢の入力をしてもらうのが面倒くさいと感じたため。

環境

誕生日はLocalDate型で年齢はInteger型とした場合。

方法

Student.java
public LocalDate getDob() {
    return dob;
}

public Integer getAge() {
    return Period.between(this.dob,LocalDate.now()).getYears();
}
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0