1
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 3 years have passed since last update.

Day.jsで誕生日から年齢を計算する

Posted at

環境

Day.js 1.8.16

コード

いろいろとやり方はあるが、diff を使うのが一番シンプル。

// input data
const birthday = {
  year: 1995,
  month: 12,
  date: 6,
};

const today = dayjs();
const { year, month, date } = birthday;
const dayjsBirthday = dayjs(`${year}-${month}-${date}`);

console.log(today.diff(dayjsBirthday, 'year'));

CodePen: https://codepen.io/ezawa800/pen/VwzJmmM

1
0
3

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
1
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?