-6

Aboutセクションのあるウェブサイトを手に入れました。私の現在の年齢を含む私についてのいくつかのテキストがあります。私は怠け者なので、誕生日ごとにその日付を変更したくありません。

生年月日に基づいて年齢を表示する簡単なスクリプトはありますか? 私はウェブ上でそのようなものを見つけませんでした。

先にThx。

4

1 に答える 1

0

ジャバスクリプトでできます。これは、あなたが始めるのに十分すぎるはずです..

// The date you were born
var birthDate = new Date(1990, 6, 19, 0, 0, 0, 0);

// The current date
var currentDate = new Date();

// The age in years
var age = currentDate.getFullYear() - birthDate.getFullYear();

// Compare the months
var month = currentDate.getMonth() - birthDate.getMonth();

// Compare the days
var day = currentDate.getDate() - birthDate.getDate();

// If the date has already happened this year
if ( month < 0 || month == 0 && day < 0 )
{
    age--;
}

alert( age );
于 2012-07-19T14:35:21.923 に答える