time intervals

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marco Alting

    time intervals

    Can anyone tell me how to write a routine that uses time-intervals, I would
    like to dynamically create an array of times like this:

    9:00
    9:30
    10:00
    10:30

    This has an interval of half an hour, but I want to be flexible for future
    use, so a variable called interval should be set to define the intervals.



  • Dr John Stockton

    #2
    Re: time intervals

    JRS: In article <tOs0b.21482$X7 3.2866381@amsne ws02.chello.com >, seen in
    news:comp.lang. javascript, Marco Alting <marco@alting-multimedia.nl>
    posted at Tue, 19 Aug 2003 17:06:33 :-[color=blue]
    >Can anyone tell me how to write a routine that uses time-intervals, I would
    >like to dynamically create an array of times like this:
    >
    >9:00
    >9:30
    >10:00
    >10:30
    >
    >This has an interval of half an hour, but I want to be flexible for future
    >use, so a variable called interval should be set to define the intervals.[/color]


    See reference in FAQ, and below.

    Assuming that you do not need times between 23:59 and when-the-clocks-
    go-back, you can use D = new Date("1/1/1 9:30") or with (D = new
    Date()) setHours(9,30,0 ,0) or D = new Date(36000000-1800000) or
    D = new Date(0,0,1,9,30 ,0) to initialise D ;
    D.setMinutes(D. getMinutes()+30 ) to increment it; and pick out the
    result with X = D.toGMTString() .match(/\d+:\d\d/).

    OTOH, you could do it as you would with pencil and paper. Start with
    HH=9 and MM=30, then
    MM += interval ; HH += Math.floor(MM/60) ; MM %= 60

    Incrementing by fractional minutes should now be obvious.

    D.setTime(D.get Time()+1800000) // alternative.

    Then assign the resulting strings to successive array elements,
    remembering to add some way of stopping.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
    <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
    <URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
    <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

    Comment

    Working...