Counter... Not Countdown

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

    Counter... Not Countdown

    Ok, I was just wondering what the code would be for something that
    tells me for example how long my relationship has been going.
    Hypothetically lets say my gal and I got together 12/7/04 @ 10:30 AM.
    And I wanted a box on my website to tell me exactly how long we have
    been together, what would the code be? Thanks for your help.

    Mike

  • Evertjan.

    #2
    Re: Counter... Not Countdown

    Mike wrote on 02 jan 2005 in comp.lang.javas cript:
    [color=blue]
    > Ok, I was just wondering what the code would be for something that
    > tells me for example how long my relationship has been going.
    > Hypothetically lets say my gal and I got together 12/7/04 @ 10:30 AM.
    > And I wanted a box on my website to tell me exactly how long we have
    > been together, what would the code be? Thanks for your help.[/color]


    Hypothetically:

    <script type='text/javascript'>
    start = new Date(2004,12-1,7,10,30)
    // 12/7/04 @ 10:30 AM
    function newdiff(){
    now = new Date()
    x = Math.floor((now-start)/1000)
    secs = x % 60
    t = ' and ' + secs + ' seconds'
    x = Math.floor(x/60)
    mins = x % 60
    t = mins + ' minutes ' + t
    x = Math.floor(x/60)
    hours = x % 24
    t = hours + ' hours, ' + t
    x = Math.floor(x/24)
    days = x
    t = days + ' days, ' + t
    document.getEle mentById('d').i nnerHTML=
    t + '<br>'
    setTimeout('new diff()',1000)
    }
    </script>

    <body onload='newdiff ()'>
    <div id='d'></div>


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Richard

      #3
      Re: Counter... Not Countdown

      Mike wrote:
      [color=blue]
      > Ok, I was just wondering what the code would be for something that
      > tells me for example how long my relationship has been going.
      > Hypothetically lets say my gal and I got together 12/7/04 @ 10:30 AM.
      > And I wanted a box on my website to tell me exactly how long we have
      > been together, what would the code be? Thanks for your help.[/color]
      [color=blue]
      > Mike[/color]

      Current time minus the start time of the relationship.





      Comment

      • Dr John Stockton

        #4
        Re: Counter... Not Countdown

        JRS: In article <Xns95D271CC233 80eejj99@194.10 9.133.29>, dated Sun, 2
        Jan 2005 10:11:11, seen in news:comp.lang. javascript, Evertjan.
        <exjxw.hannivoo rt@interxnl.net > posted :

        I see you are assuming the OP to be an American !
        [color=blue]
        > start = new Date(2004,12-1,7,10,30)[/color]

        or new Date("2004/12/07 10:30") ,

        which is IMHO more legible, I believe always accepted, and in the spirit
        of ISO and FIPS.
        [color=blue]
        > x = Math.floor((now-start)/1000)
        > secs = x % 60
        > t = ' and ' + secs + ' seconds'
        > x = Math.floor(x/60)[/color]

        Since secs is known, the last line could be x = (x-secs)/60 ;
        that's shorter, ought to be (insignificantl y) quicker, and should not
        give any rounding-error problems.

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
        <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

        Comment

        • Evertjan.

          #5
          Re: Counter... Not Countdown

          Dr John Stockton wrote on 02 jan 2005 in comp.lang.javas cript:[color=blue]
          > I see you are assuming the OP to be an American ![/color]

          Yes, three reasons:

          1
          OP's IP 67.184.110.78 is
          c-67-184-110-78.client.comca st.net of comcast in in NJ, USA

          2
          "Mike" <mikekolb@comca st.net> points to USA

          3
          12/07/2004 as 7 December is more recent than as 12 July
          and fresh love is more demanding, even for code like in the OQ.
          [color=blue][color=green]
          >> start = new Date(2004,12-1,7,10,30)[/color]
          >
          > or new Date("2004/12/07 10:30") ,
          >
          > which is IMHO more legible, I believe always accepted,
          > and in the spirit of ISO and FIPS.[/color]

          I did not want to introduce the old argument of datestrings here.
          [color=blue][color=green]
          >> x = Math.floor((now-start)/1000)[/color][/color]

          In fact more correct [.5 sec max] would be:

          x = Math.round((now-start)/1000)

          But since the start time is probably not recorded with enough accuracy ..
          [color=blue][color=green]
          >> secs = x % 60
          >> t = ' and ' + secs + ' seconds'
          >> x = Math.floor(x/60)[/color]
          >
          > Since secs is known, the last line could be x = (x-secs)/60 ;
          > that's shorter, ought to be (insignificantl y) quicker, and should not
          > give any rounding-error problems.[/color]

          Yes, same quality.

          --
          Evertjan.
          The Netherlands.
          (Please change the x'es to dots in my emailaddress)

          Comment

          • Dr John Stockton

            #6
            Re: Counter... Not Countdown

            JRS: In article <cr9idt0qgm@new s2.newsguy.com> , dated Sun, 2 Jan 2005
            13:35:18, seen in news:comp.lang. javascript, Richard <Anonymous@127. 001>
            posted :[color=blue]
            > Mike wrote:
            >[color=green]
            >> Ok, I was just wondering what the code would be for something that
            >> tells me for example how long my relationship has been going.
            >> Hypothetically lets say my gal and I got together 12/7/04 @ 10:30 AM.
            >> And I wanted a box on my website to tell me exactly how long we have
            >> been together, what would the code be? Thanks for your help.[/color]
            >[color=green]
            >> Mike[/color]
            >
            >Current time minus the start time of the relationship.
            >
            >http://www.javascriptkit.com/script/.../countup.shtml[/color]

            It is better to give the code here, if not too long (in this case, the
            code *should* be short). It is then much more likely to get checked by
            the regulars; remember, much of the code that can be found by Google is
            bloated, wrong, or both.

            --
            © John Stockton, Surrey, UK. ???@merlyn.demo n.co.uk Turnpike v4.00 MIME. ©
            Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
            Check boilerplate spelling -- error is a public sign of incompetence.
            Never fully trust an article from a poster who gives no full real name.

            Comment

            • Dr John Stockton

              #7
              Re: Counter... Not Countdown

              JRS: In article <Xns95D374726C6 93eejj99@194.10 9.133.29>, dated Mon, 3
              Jan 2005 10:27:13, seen in news:comp.lang. javascript, Evertjan.
              <exjxw.hannivoo rt@interxnl.net > posted :[color=blue]
              >[color=green][color=darkred]
              >>> start = new Date(2004,12-1,7,10,30)[/color]
              >>
              >> or new Date("2004/12/07 10:30") ,
              >>
              >> which is IMHO more legible, I believe always accepted,
              >> and in the spirit of ISO and FIPS.[/color]
              >
              >I did not want to introduce the old argument of datestrings here.[/color]


              My belief is that I've asserted the safety of the above string form
              often enough that, if it were not safe, someone would by now have said
              so. And there's benefit in displaying the use of the logical order.

              ISTM that the undesirability of using in such a string DD/MM/YYYY and
              MM/DD/YYYY is unarguably sound; even if javascript always takes it as
              the latter, any person outside the USA is liable to misinterpret it.

              --
              © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk DOS 3.3, 6.20; Win98. ©
              Web <URL:http://www.merlyn.demo n.co.uk/> - FAQqish topics, acronyms & links.
              PAS EXE TXT ZIP via <URL:http://www.merlyn.demo n.co.uk/programs/00index.htm>
              My DOS <URL:http://www.merlyn.demo n.co.uk/batfiles.htm> - also batprogs.htm.

              Comment

              • Evertjan.

                #8
                Re: Counter... Not Countdown

                Dr John Stockton wrote on 03 jan 2005 in comp.lang.javas cript:
                [color=blue]
                > JRS: In article <Xns95D374726C6 93eejj99@194.10 9.133.29>, dated Mon, 3
                > Jan 2005 10:27:13, seen in news:comp.lang. javascript, Evertjan.
                > <exjxw.hannivoo rt@interxnl.net > posted :[color=green]
                >>[color=darkred]
                >>>> start = new Date(2004,12-1,7,10,30)
                >>>
                >>> or new Date("2004/12/07 10:30") ,
                >>>
                >>> which is IMHO more legible, I believe always accepted,
                >>> and in the spirit of ISO and FIPS.[/color]
                >>
                >>I did not want to introduce the old argument of datestrings here.[/color]
                >
                >
                > My belief is that I've asserted the safety of the above string form
                > often enough that, if it were not safe, someone would by now have said
                > so. And there's benefit in displaying the use of the logical order.
                >
                > ISTM that the undesirability of using in such a string DD/MM/YYYY and
                > MM/DD/YYYY is unarguably sound; even if javascript always takes it as
                > the latter, any person outside the USA is liable to misinterpret it.
                >[/color]

                John, I fully agree with your point of view on yyyymmdd.

                I just didn't want to introduce any argument on that, since the OQ was
                about date difference, and I did not want to shigt the focus.

                I failed.

                --
                Evertjan.
                The Netherlands.
                (Please change the x'es to dots in my emailaddress)

                Comment

                Working...