石田修二ホームページ > JavaScript講座 > (サイト内検索)
ソースは次の通り。
var year = 1972 //生まれた年 var month = 5 //月 var day = 19 //日 var now = new Date() var today = new Date(now.getYear(), now.getMonth(), now.getDate()) var thisYear = now.getYear() var thisBirthDay = new Date(thisYear, month-1, day) var theYear = thisYear if(thisBirthDay < today) { theYear = thisYear+1 } var myAge = theYear - year var theDay = new Date(theYear, month-1, day) var timeToGo = theDay - today var daysToGo = ((timeToGo >= 0) ? Math.ceil(timeToGo/86400000) : "") if(daysToGo == 0) { var msg = "今日は石田修二の誕生日です!" } else { var msg = "石田修二の誕生日(5月19日)まであと" + daysToGo + "日!" } // 結果を表示 document.write(msg)
リンクはご自由にどうぞ。
Last modified: 2014-02-21 00:42:04