Aboutセクションのあるウェブサイトを手に入れました。私の現在の年齢を含む私についてのいくつかのテキストがあります。私は怠け者なので、誕生日ごとにその日付を変更したくありません。
生年月日に基づいて年齢を表示する簡単なスクリプトはありますか? 私はウェブ上でそのようなものを見つけませんでした。
先にThx。
Aboutセクションのあるウェブサイトを手に入れました。私の現在の年齢を含む私についてのいくつかのテキストがあります。私は怠け者なので、誕生日ごとにその日付を変更したくありません。
生年月日に基づいて年齢を表示する簡単なスクリプトはありますか? 私はウェブ上でそのようなものを見つけませんでした。
先にThx。
ジャバスクリプトでできます。これは、あなたが始めるのに十分すぎるはずです..
// 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 );