Display current time

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

    #1

    Display current time

    How do you do this. I would like for it to be as dynamic as each page
    refresh.
    Thanks


  • McKirahan

    #2
    Re: Display current time

    " JCO" <J.Oliviero@ver izon.net> wrote in message
    news:ZWjWb.4514 $1B6.1419@nwrdd c03.gnilink.net ...[color=blue]
    > How do you do this. I would like for it to be as dynamic as each page
    > refresh.
    > Thanks[/color]


    Will this help? Test as-is; watch for word-wrap.

    <html>
    <head>
    <title>time.htm </title>
    </head>
    <body>
    <script type="text/javascript">
    document.write( '<span id="clock"></span>');
    isNS4 = (document.layer s) ? true : false;
    isIE4 = (document.all && !document.getEl ementById) ? true : false;
    isIE5 = (document.all && document.getEle mentById) ? true : false;
    isNS6 = (!document.all && document.getEle mentById) ? true : false;
    var clock = "";
    if (isNS4) {
    clock = document.layers["clock"];
    } else if (isIE4) {
    clock = document.all["clock"];
    } else if (isIE5 || isNS6) {
    clock = document.getEle mentById("clock ");
    }
    function clockTick() {
    var Now = new Date();
    var Nhh = Now.getHours();
    var Nnn = Now.getMinutes( );
    if (Nnn < 10) Nnn = "0" + Nnn;
    var Nss = Now.getSeconds( );
    if (Nss < 10) Nss = "0" + Nss;
    var Nap = "AM";
    if (Nhh >= 12) {
    Nhh -= 12;
    Nap = "PM";
    }
    if (Nhh == 0) Nhh = 12;
    var Str = new Array();
    Str[0] = "<font color='#000000' >";
    Str[9] = Nhh;
    Str[10] = ":";
    Str[11] = Nnn;
    Str[12] = ":";
    Str[13] = Nss;
    Str[14] = " ";
    Str[15] = Nap;
    Str[16] = "</font> &nbsp; ";
    var Clock = Str.join("");
    clock.innerHTML = Clock;
    }
    setInterval("cl ockTick()",1000 );
    </script>
    </body>
    </html>


    P.S. I'm sure someone will "refine" it!


    Comment

    • Randy Webb

      #3
      Re: Display current time

      McKirahan wrote:
      [color=blue]
      > " JCO" <J.Oliviero@ver izon.net> wrote in message
      > news:ZWjWb.4514 $1B6.1419@nwrdd c03.gnilink.net ...
      >[color=green]
      >>How do you do this. I would like for it to be as dynamic as each page
      >>refresh.
      >>Thanks[/color]
      >
      >
      >
      > Will this help? Test as-is; watch for word-wrap.
      >
      > <html>
      > <head>
      > <title>time.htm </title>
      > </head>
      > <body>
      > <script type="text/javascript">
      > document.write( '<span id="clock"></span>');
      > isNS4 = (document.layer s) ? true : false;
      > isIE4 = (document.all && !document.getEl ementById) ? true : false;[/color]

      IE4 is not the only browser that can pass that test.
      [color=blue]
      > isIE5 = (document.all && document.getEle mentById) ? true : false;[/color]

      IE5+ is not the only browser that can pass that test.
      [color=blue]
      > isNS6 = (!document.all && document.getEle mentById) ? true : false;[/color]

      And NS6 is definitely not the only browser that passes that test.
      [color=blue]
      > P.S. I'm sure someone will "refine" it![/color]

      Doubtful. Discredit it maybe.

      Consult the FAQ with regards to dynamically changing page content, it
      has its own section. As written, your code will utterly fail in NN4.xx
      as it doesn't support innerHTML in any fashion.


      --
      Randy
      Chance Favors The Prepared Mind
      comp.lang.javas cript FAQ - http://jibbering.com/faq/

      Comment

      • McKirahan

        #4
        Re: Display current time

        "Randy Webb" <hikksnotathome @aol.com> wrote in message
        news:6bqdnQOOFv TXubfdRVn-vA@comcast.com. ..[color=blue]
        > McKirahan wrote:[color=green]
        > > P.S. I'm sure someone will "refine" it![/color]
        >
        > Doubtful. Discredit it maybe.[/color]


        You would have helped the OP if you had refined the solution offered rather
        than just discrediting it.


        Comment

        • Richard Cornford

          #5
          Re: Display current time

          "McKirahan" <News@McKirahan .com> wrote in message
          news:%qqWb.5841 $_44.9944@attbi _s52...[color=blue][color=green][color=darkred]
          >>>P.S. I'm sure someone will "refine" it![/color]
          >>
          >>Doubtful. Discredit it maybe.[/color]
          >
          >You would have helped the OP if you had refined the solution
          >offered rather than just discrediting it.[/color]

          It wasn't necessarily Randy's intention to help the OP. This isn't,
          after all, a help desk, it is a discussion forum. OPs actually getting
          help is just a pleasant side effect of that.

          The real benefit in the group goes to the regular participants, who you
          appear to have decided to join. And to receive that benefit you will
          have to be willing to be criticised because if nobody tells you when you
          are wrong you will never know how or what you can improve. And then, if
          you don't believe that you are not wrong, you can always argue your
          case. Though not in this instance as the object inference style of
          scripting is completely discredited.

          Thinking back to when I started positing in this group, I thought I
          understood javascript fairly well. I was very wrong but I needed some
          hindsight to appreciate that, and people pointing out where and why I
          was wrong. I also needed to react by taking what I was being told on
          board and going away and re-doing and re-posting the scripts that had
          been criticised until they were right. I learnt a great deal doing that,
          more than I had expected was possible.

          If you reacted to Randy's comments by identifying what is wrong with
          your object inference script and replaced it with a feature detecting
          equivalent and posted that you would probably learn something useful
          along the way, and the OP would then also benefit. (Though I think your
          code is well outside the rather inadequate spec originally posted.)

          The relevant part of the FAQ is:-

          <URL: http://jibbering.com/faq/#FAQ4_26 >

          - which links to quite a good page at apple. The next revision of the
          FAQ will also reference a new page, the draft of which is at:-

          <URL:
          http://www.litotes.demon.co.uk/js_in...er_detect.html[color=blue]
          >[/color]

          The section on inserting content is:-

          <URL: http://jibbering.com/faq/#FAQ4_15 >

          - and will also have notes added with the next revision:-

          <URL: http://www.litotes.demon.co.uk/js_in..._dynwrite.html[color=blue]
          >[/color]

          - and may eventually be joined by a page on W3C DOM methods, which you
          could investigate in this context as you would only be sacrificing
          support for IE 4 if you used those. (Specifically, re-setting the
          nodeValue property of the text node within the SPAN element as that is a
          lot more efficient than re-writing its innerHTML).

          Richard.


          Comment

          • Randy Webb

            #6
            Re: Display current time

            McKirahan wrote:[color=blue]
            > "Randy Webb" <hikksnotathome @aol.com> wrote in message
            > news:6bqdnQOOFv TXubfdRVn-vA@comcast.com. ..
            >[color=green]
            >>McKirahan wrote:
            >>[color=darkred]
            >>>P.S. I'm sure someone will "refine" it![/color]
            >>
            >>Doubtful. Discredit it maybe.[/color]
            >
            >
            >
            > You would have helped the OP if you had refined the solution offered rather
            > than just discrediting it.[/color]

            The only way to "refine" that script is to discard it and start over.
            The reference to the FAQ (and reading it) will do both of you way more
            good than me writing a clock script will ever do.

            Just for kicks and giggles, you can look at <URL:
            http://www.hikksworld.com/clock.html /> though. Its one I made a while
            back that has some other things on it, but the clock is there.

            --
            Randy
            Chance Favors The Prepared Mind
            comp.lang.javas cript FAQ - http://jibbering.com/faq/

            Comment

            • Dr John Stockton

              #7
              Re: Display current time

              JRS: In article <e4kWb.2985$jk2 .14236@attbi_s5 3>, seen in
              news:comp.lang. javascript, McKirahan <News@McKirahan .com> posted at Wed,
              11 Feb 2004 06:36:58 :-[color=blue]
              >" JCO" <J.Oliviero@ver izon.net> wrote in message
              >news:ZWjWb.451 4$1B6.1419@nwrd dc03.gnilink.ne t...[/color]
              [color=blue][color=green]
              >> How do you do this. I would like for it to be as dynamic as each page
              >> refresh.[/color][/color]
              [color=blue]
              >isNS4 = (document.layer s) ? true : false;[/color]


              You cannot identify browsers in that manner. To some extent, you can
              determine the nature of a browser : what it is-or-resembles. To reflect
              this, change "isNS4" to "asNS4", etc. But read RC's FAQ notes.

              setInterval(... , 1000) does not fire once per second, in at least some
              systems. Read the FAQ.

              The OP asked for the time to be shown at each page refresh, not
              continuously. A mere document.write( new Date()) will do that.

              The following can be used for converting proper hours to Merkin ones :
              Nap = ["AM","PM"][+(Nhh>11)]
              Nhh = 1 + (Nhh+11)%12
              Partially tested.

              --
              © 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> jscr maths, dates, sources.
              <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

              Comment

              • JCO

                #8
                Re: Display current time

                Thanks everyone for your comments.
                I have what I need.

                "Dr John Stockton" <spam@merlyn.de mon.co.uk> wrote in message
                news:jr8EWxCz$i KAFwtV@merlyn.d emon.co.uk...[color=blue]
                > JRS: In article <e4kWb.2985$jk2 .14236@attbi_s5 3>, seen in
                > news:comp.lang. javascript, McKirahan <News@McKirahan .com> posted at Wed,
                > 11 Feb 2004 06:36:58 :-[color=green]
                > >" JCO" <J.Oliviero@ver izon.net> wrote in message
                > >news:ZWjWb.451 4$1B6.1419@nwrd dc03.gnilink.ne t...[/color]
                >[color=green][color=darkred]
                > >> How do you do this. I would like for it to be as dynamic as each page
                > >> refresh.[/color][/color]
                >[color=green]
                > >isNS4 = (document.layer s) ? true : false;[/color]
                >
                >
                > You cannot identify browsers in that manner. To some extent, you can
                > determine the nature of a browser : what it is-or-resembles. To reflect
                > this, change "isNS4" to "asNS4", etc. But read RC's FAQ notes.
                >
                > setInterval(... , 1000) does not fire once per second, in at least some
                > systems. Read the FAQ.
                >
                > The OP asked for the time to be shown at each page refresh, not
                > continuously. A mere document.write( new Date()) will do that.
                >
                > The following can be used for converting proper hours to Merkin ones :
                > Nap = ["AM","PM"][+(Nhh>11)]
                > Nhh = 1 + (Nhh+11)%12
                > Partially tested.
                >
                > --
                > © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE[/color]
                4 ©[color=blue]
                > <URL:http://jibbering.com/faq/> Jim Ley's FAQ for[/color]
                news:comp.lang. javascript[color=blue]
                > <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates,[/color]
                sources.[color=blue]
                > <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items,[/color]
                links.


                Comment

                Working...