トップページに戻る    次のJavaScriptのサンプルへ    前のJavaScriptのサンプルへ

2-1 カレンダーを出力

JavaScriptのサンプル

カレンダーを出力します。


ソース

var nowDate = new Date();

var targetYear;
var targetMonth;
var targetDay;

nowDate.setDate(nowDate.getDate() + 60);

for (i = 1; i < 120; i++){
    nowDate.setDate(nowDate.getDate() - 1);

    targetYear  = nowDate.getFullYear();

    targetMonth = nowDate.getMonth()+1;
    if (targetMonth < 10) targetMonth = "0" + targetMonth;

    targetDay   = nowDate.getDate();
    if (targetDay < 10) targetDay = "0" + targetDay;

    WScript.Echo("" + targetYear + "年" + targetMonth + "月" + targetDay + "日");
}


実行結果

作成中


解説

前後2ヶ月の日付を出力してます。