Solved

Increment time by 30 minutes in loop

Posted on 2008-10-30
5
1,425 Views
Last Modified: 2012-05-05
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
Comment
Question by:saturation
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
Pawel Witkowski earned 500 total points
ID: 22846696
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
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 22847426
"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
 

Author Comment

by:saturation
ID: 22850113
Web page.
0
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 22852285
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
 
LVL 18

Expert Comment

by:Pawel Witkowski
ID: 22852742
saturation did you chcecked what i gave you ? Or you need something completly diffrent ?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question