Announcement

Collapse
No announcement yet.

How to show local time and date

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to show local time and date

    Well I am not interested in getting time and date from users computer for my web site because sometime it does not give the right information. So do you have any other idea how I can get local time and date (approximately accurate) for my web site. Necessary code will be very helpfull. Thank you.

  • #2
    Can't be done with pure HTML.

    However there are three alternatives:

    PHP -> http://de.php.net/manual/en/function.time.php

    SSI -> http://members.tripod.com/DarrenCGI/ssi_time.html

    Javascript -> http://www.computerhope.com/j2.htm
    That's the end of that!

    Comment


    • #3
      MrNase,

      Thank you for providing the web link for showing date and time on the web page. Well I an using the following web link.
      Javascript -> http://www.computerhope.com/j2.htm

      The output of this code is the following:

      Todays Date: 8/9/104
      Todays Time: 10:03 A.M.

      But I would like to show Today's Date in stead of Todays. Can you help me. Thank you.

      Comment


      • #4
        I believe all you would have to do is change the line:

        document.write('<B>Todays Time:</b> ' + Hours + ":" + Mins + Time + '');

        to

        document.write('<B>Today's Time:</b> ' + Hours + ":" + Mins + Time + '');

        The "write" statement is followed by what is "written." You want it to be Today's" instead of "Todays".

        And if you change the First line:

        <b>Todays Date: </b><SCRIPT LANGUAGE="JavaScript">

        to

        <b>Today's Date: </b><SCRIPT LANGUAGE="JavaScript">

        it will write: "Today's Date" instead of "Todays Date."

        Not too complicated. :-)

        Regards,
        Last edited by slappy; Mon 9th Aug '04, 12:00pm.
        Slappy

        Comment


        • #5
          Now working with a new code for showing date and time. It works perfectly when JS code in under the html tag. But I would like to keep the JS code in an external file and call the file inside the html. I tired to do so but it's giving me error and the blinker is not blinking when I tried. Any suggestion. Thank you.

          Code:
          <HTML>
          <HEAD>
          <title>DCScript© Digital Clock</title>
          <style>
          .clock {
          background-color: #A6A98D;
          color: black;
          font-family: verdana;
          float: center;
          border: 1px solid black;
          border-collapse: collapse;
          }
          .time {
          font-size: 100;
          }
          .clock TD {
          border: 1px solid black;
          border-collapse: collapse;
          }
          B {color:black}
          BODY {font-family: arial; font-size: 10pt}
          </style>
          <SCRIPT LANGUAGE="JavaScript">
          function time() {
          var today = new Date();
          var hrs = today.getHours();
          var min = today.getMinutes();
          var secs = today.getSeconds();
          var alsohrs = today.getHours();
          var dayNumber = today.getDate();
          var year = today.getFullYear();
          var ampm="";
          var zero="0";
          var month = today.getMonth() +1;
          var weekday = today.getDay();
          var wdn = new Array(7)
          wdn[0] = "SUN";
          wdn[1] = "MON";
          wdn[2] = "TUE";
          wdn[3] = "WED";
          wdn[4] = "THU";
          wdn[5] = "FRI";
          wdn[6] = "SAT";
          //Statement that puts '0's in front of single minutes or seconds.
          if (min<10)
          {
          min=zero+min;
          }
          if (secs<10)
          {
          secs=zero+secs;
          }
          //Statement that eliminates Metric Time
          if (hrs>12)
          {
          hrs=eval(hrs - 12);
          }
          if (hrs>=0 && hrs<1)
          {
          hrs=12
          }
          //P.M. Statement
          if (alsohrs>=12 && alsohrs<24)
          {
          ampm="P.M.";
          }
          //A.M. Statement
          if (alsohrs<12 && alsohrs>=0)
          {
          ampm="A.M.";
          }
          tmp='<table width="60%" class="clock"><tr><td class="time" colspan="4">';
          tmp+=hrs+'<span id="blinker">:</span>'+min;
          tmp+='<font size="20"> '+ampm+'</font>';
          tmp+='<tr><td><font size="-1">Month</font><br><b>'+month+'</b></td>';
          tmp+='<td><font size="-1">Date</font><br><b>'+dayNumber+'</b></td>';
          tmp+='<td><font size="-1">Day</font><br><b>'+wdn[weekday]+'</b></td>';
          tmp+='<td><font size="-1">Year</font><br><b>'+year+'</b></td></tr></table>';
          document.getElementById("clockgoeshere").innerHTML=tmp;
          clocktime=setTimeout("time()","1000");
          }
          function blink() {
          var obj = document.getElementById("blinker");
          if (obj.style.visibility == "visible") {
          obj.style.visibility="hidden";
          }
          else {
          obj.style.visibility="visible";
          }
          eachsecond=setTimeout("blink()","500");
          }
          </SCRIPT>
          </head>
          <body onLoad="time(); blink();"> <center>
          <div id="clockgoeshere"></div><p>
          </center>
          </body>
          </body>
          </html>

          Comment


          • #6
            I have 2 files:

            Code:
             <HTML>
             <HEAD>
             <title>DCScript© Digital Clock</title>
             <style>
             .clock {
             background-color: #A6A98D;
             color: black;
             font-family: verdana;
             float: center;
             border: 1px solid black;
             border-collapse: collapse;
             }
             .time {
             font-size: 100;
             }
             .clock TD {
             border: 1px solid black;
             border-collapse: collapse;
             }
             B {color:black}
             BODY {font-family: arial; font-size: 10pt}
             </style>
             <script src="script.js" type="text/javascript">
             
             </script>
             </head>
             <body onLoad="time(); blink();"> <center>
             <div id="clockgoeshere"></div><p>
             </center>
             </body>
             </body>
             </html>
            and a script.js:
            Code:
             function time() {
             var today = new Date();
             var hrs = today.getHours();
             var min = today.getMinutes();
             var secs = today.getSeconds();
             var alsohrs = today.getHours();
             var dayNumber = today.getDate();
             var year = today.getFullYear();
             var ampm="";
             var zero="0";
             var month = today.getMonth() +1;
             var weekday = today.getDay();
             var wdn = new Array(7)
             wdn[0] = "SUN";
             wdn[1] = "MON";
             wdn[2] = "TUE";
             wdn[3] = "WED";
             wdn[4] = "THU";
             wdn[5] = "FRI";
             wdn[6] = "SAT";
             //Statement that puts '0's in front of single minutes or seconds.
             if (min<10)
             {
             min=zero+min;
             }
             if (secs<10)
             {
             secs=zero+secs;
             }
             //Statement that eliminates Metric Time
             if (hrs>12)
             {
             hrs=eval(hrs - 12);
             }
             if (hrs>=0 && hrs<1)
             {
             hrs=12
             }
             //P.M. Statement
             if (alsohrs>=12 && alsohrs<24)
             {
             ampm="P.M.";
             }
             //A.M. Statement
             if (alsohrs<12 && alsohrs>=0)
             {
             ampm="A.M.";
             }
             tmp='<table width="60%" class="clock"><tr><td class="time" colspan="4">';
             tmp+=hrs+'<span id="blinker">:</span>'+min;
             tmp+='<font size="20"> '+ampm+'</font>';
             tmp+='<tr><td><font size="-1">Month</font><br><b>'+month+'</b></td>';
             tmp+='<td><font size="-1">Date</font><br><b>'+dayNumber+'</b></td>';
             tmp+='<td><font size="-1">Day</font><br><b>'+wdn[weekday]+'</b></td>';
             tmp+='<td><font size="-1">Year</font><br><b>'+year+'</b></td></tr></table>';
             document.getElementById("clockgoeshere").innerHTML=tmp;
             clocktime=setTimeout("time()","1000");
             }
             function blink() {
             var obj = document.getElementById("blinker");
             if (obj.style.visibility == "visible") {
             obj.style.visibility="hidden";
             }
             else {
             obj.style.visibility="visible";
             }
             eachsecond=setTimeout("blink()","500");
             }
            and it works for me
            That's the end of that!

            Comment


            • #7
              Just A Note...

              I just found a way to do this, may be another option for someone. PHP/JS code will show a live clock with date for any timezone. ATM I’ve my code showing the time and day/date in my hometown of Murmansk (UCT+3).

              My original problem: http://www.codingforums.com/showthre...2&page=1&pp=15

              My final solution: http://arctic.ithium.net/clock.php (upper right)

              Comment


              • #8
                Originally posted by szms
                But I would like to show Today's Date in stead of Todays. Can you help me. Thank you.
                Sorry! I just caught this one...

                Copy and paste:

                document.write('<B>Today\'s Time:</b> ' + Hours + ':'+ Mins + Time + ');


                ...that slash (\) in front of the apostrophe is what keeps the JavaScript from closing.
                The single quotes in red were edited for clarity; just looked out of place.
                Last edited by Arctic Fox; Mon 4th Oct '04, 8:04pm.

                Comment

                widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                Working...
                X