0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

生年月日から年齢の求めかた

Posted at

よく使うので、メモ。
誕生日と現在日をyyyyMMdd形式で引き算して10000で割ることで求められる。

//誕生日
Calendar cal = Calendar.getInstance();
cal.set(2000,01,01,10,00,00);

//計算用にフォーマットを揃える
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

//現在日 - 誕生日 を10000で割る
int age = (Integer.parseInt(sdf.format(new Date())) - Integer.parseInt(sdf.format(cal.getTime()))) / 10000;
0
0
0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?