keitahirai
3/23/2014 - 2:30 PM

アクセス時間によりメッセージ変更

アクセス時間によりメッセージ変更

// 1時間おきにするには1ずつ、2時間おきには2ずつ、6時間おきには6ずつ数字を増やす
h = (new Date()).getHours();
if((h >=  0) && (h <  3)) document.write("午前0時を回りました");
if((h >=  3) && (h <  6)) document.write("もうすぐ夜が明けますね");
if((h >=  6) && (h <  9)) document.write("おはようございます");
if((h >=  9) && (h < 12)) document.write("お昼ごはんは何にしましょう");
if((h >= 12) && (h < 15)) document.write("眠くなってくる頃ですね");
if((h >= 15) && (h < 18)) document.write("お仕事頑張ってますか");
if((h >= 18) && (h < 21)) document.write("こんばんは 夜になりました");
if((h >= 21) && (h < 24)) document.write("もうすぐ寝る時間です");