Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1659
  • Last Modified:

Increment time by 30 minutes in loop

I am building out a schedule and need to create a loop where it prints out the time every 30 minutes between 7 am and 11 pm.  So, it would look something like the following:

7:00 a.m.
7:30 a.m.
8:00 a.m.
... (rest of the times here)
12:00 p.m.
12:30 p.m.
...(rest of the times here)
11:00 p.m.

How can I do this?  I have no idea where to start.
0
saturation
Asked:
saturation
  • 2
  • 2
1 Solution
 
Pawel WitkowskiSenior Javascript DeveloperCommented:
chceck this :)
function printSchedule() 
{
 
var element = document.createElement('div');
 
for (var i=7;i<=23;i++)
{
   var amPm=(i<13)?"a.m.":"p.m.";
   var j=(i>12)?i-12:i;
   element.innerHTML+=j+":00 "+amPm +"<br>";
   element.innerHTML+=j+":30 "+amPm +"<br>";
}
 
return element;
 
}
 
document.body.appendChild(printSchedule())

Open in new window

0
 
scrathcyboyCommented:
"where it prints out the time every 30 minutes between 7 am and 11 pm."

Prints?  Where?  To paper?  To a web page?  To the user's screen?    Be specific
0
 
saturationAuthor Commented:
Web page.
0
 
scrathcyboyCommented:
javascript --

setInterval('showTime()', 1800000);

See here for a complete example of this function, that will do what you ask --
http://www.w3schools.com/HTMLDOM/met_win_setinterval.asp
0
 
Pawel WitkowskiSenior Javascript DeveloperCommented:
saturation did you chcecked what i gave you ? Or you need something completly diffrent ?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now