Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1536 How do I create a Javascript that if it is before a specific time (for example, 9 am) it will display tomorrow's day but will show the day AFTER tomorrow day if it is after that specific time?

You are here: irt.org | FAQ | JavaScript | Date | Q1536 [ previous next ]

Try:

<script language="JavaScript"><!--
var splitTime = (8*60)+59;
var days = new Array('sun','mon','tue','wed','thu','fri','sat');
var now = new Date();
var dayNum = now.getDay(); // 0 = sun -> 6 = sat
var nowTime = (now.getHours()*60) + now.getMinutes();
if (nowTime < splitTime) dayNum-=1;
else if (nowTime > splitTime) dayNum+=1;
if (dayNum < 0) dayNum = 6;
if (dayNum > 6) dayNum = 0;
document.write(days[dayNum]);
//--></script>

©2018 Martin Webb