๋ชฉ์ฐจ

[java]์๋ ์์ผ๋ก ๋ง๋์ด ๊ณ์ฐ ์์
์๋ ์์ผ๋ก ๋ง๋์ด ๊ตฌํ๋ ์์ ์์ค์ด๋ค.
public static int getAgeByBirthday(String birthDay) {
// param๊ฐ์ "2000-01-01" ํ์
์ ๋ฐ์ดํฐ๋ผ๋ ๊ฐ์
String birth = StrUtils.replace(birthDay, "-", "");
// ๋
,์,์ผ ์๋ฅด๊ธฐ
int birth_year = StrUtils.parseInt(StrUtils.substring(birth, 0, 4));
int birth_month = StrUtils.parseInt(StrUtils.substring(birth, 4, 6));
int birth_day = StrUtils.parseInt(StrUtils.substring(birth, 6, 8));
Calendar current = Calendar.getInstance();
// ํ์ฌ๋
, ์, ์ผ get
int current_year = current.get(Calendar.YEAR);
int current_month = current.get(Calendar.MONTH) + 1;
int current_day = current.get(Calendar.DAY_OF_MONTH);
int age = current_Year - birth_Year;
// ๋ง๋์ด
if (birth_month * 100 + birth_day > current_month * 100 + current_day) {
age--;
}
return age;
}

'IT > development' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [jQuery] jQuery ๋ฒํผ ํด๋ฆญ ์ table tr ์จ๊น์ฒ๋ฆฌ (1) | 2022.11.24 |
|---|---|
| [WAS]apache tomcat ์์ฒญ ํ๊ฒ์์ ์ ํจํ์ง ์์ ๋ฌธ์๊ฐ... (0) | 2022.11.24 |
| [jQuery] jQuery CDN ํญ์ ์ต์ ์ผ๋ก ๋ถ๋ฌ์ค๊ธฐ... (1) | 2022.11.24 |
| [WAS] Apache Tomcat ํ๊ธ ๊นจ์ง(์ธ์ฝ๋ฉ ๋ฌธ์ ) (0) | 2022.11.24 |
| Cannot create JDBC driver of class 'net.sf.log4jdbc.sql.jdbcapi.DriverSpy'... (0) | 2022.11.24 |
๋๊ธ