Results 1 to 4 of 4

Thread: Display the date/time in various places on my website page

  1. #1
    Join Date
    Sep 2004
    Location
    Little Falls, Roodepoort, South Africa
    Posts
    406
    Thanks
    4
    Thanked 1 Time in 1 Post

    Red face Display the date/time in various places on my website page

    Hi

    I need to display the date/time in various places on my website page, I have some script that should work but does not for some reason.

    I created a fiddle for you to see test etc.

    [URL="https://jsfiddle.net/0rbtugjo/3/[/URL]

    Script is:
    Code:
    <script type="text/javascript">
    function GetClock(){var d=new Date();var nmonth=d.getMonth(),ndate=d.getDate(),nyear=d.getFullYear();var nhour=d.getHours(),nmin=d.getMinutes();if(nmin<=9) nmin="0"+nmin
    
    var obj=document.querySelectorAll('.privclock);for(var i in obj){obj[i].innerHTML=""+ndate+"/"+(nmonth+1)+"/"+nyear+" "+nhour+":"+nmin+"";}
    
    window.onload=function(){GetClock();setInterval(GetClock,1000);}</script>
    And basic html is
    Code:
    <div class="privclock"></div>
    rgds, Simon
    Very Best Rgds, Simonf :cool:
    __________________________________
    My Site | E-Mail Me

  2. #2
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,089
    Thanks
    1
    Thanked 205 Times in 201 Posts

    Default

    Hi there simonf,

    does this help...

    Code:
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
    
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">
    
    <title>untitled document</title>
    
    <link rel="stylesheet" href="screen.css" media="screen">
    
    </head>
    <body> 
    
     <div class="privclock"></div>
     <div class="privclock"></div>
     <div class="privclock"></div>
     <div class="privclock"></div>
     <div class="privclock"></div>
     <div class="privclock"></div>
     <div class="privclock"></div>
     <div class="privclock"></div>
    
    <script>
    (function() {
       'use strict';
    
    function GetClock(){
       var obj = document.querySelectorAll('.privclock'),i;
       var d = new Date();
       var nmonth = d.getMonth(), ndate = d.getDate(), nyear = d.getFullYear();
       var nhour = d.getHours(), nmin = d.getMinutes();
          if( nmin <= 9 ) { 
             nmin = '0' + nmin;
          }
          for( i = 0; i < obj.length; i ++ ) {
             obj[i].textContent = ndate + '/' + (nmonth+1) + '/' + nyear + ' ' + nhour + ':' + nmin;
          }
       }
       GetClock();
       setInterval( GetClock, 1000 );
    }());
    </script>
    
    </body>
    </html>

    coothead
    ~ the original bald headed old fart ~

  3. The Following User Says Thank You to coothead For This Useful Post:

    simonf (07-21-2017)

  4. #3
    Join Date
    Sep 2004
    Location
    Little Falls, Roodepoort, South Africa
    Posts
    406
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    Hi Coothead

    Perfects mate...... many many thanks.........
    Very Best Rgds, Simonf :cool:
    __________________________________
    My Site | E-Mail Me

  5. #4
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,089
    Thanks
    1
    Thanked 205 Times in 201 Posts

    Default


    No problem, you're very welcome.

    coothead
    ~ the original bald headed old fart ~

Similar Threads

  1. Change display of date for Local Time Script
    By Foundas in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 10-19-2011, 04:26 PM
  2. Date/Time Display Issue
    By tomyknoker in forum PHP
    Replies: 1
    Last Post: 03-14-2007, 06:41 PM
  3. Need Help changing a script's date/time display
    By toastysquirrel in forum PHP
    Replies: 1
    Last Post: 10-17-2006, 05:14 AM
  4. Display content depending on time/date
    By jonasb in forum JavaScript
    Replies: 0
    Last Post: 03-14-2006, 11:46 AM
  5. Local Time - date display?
    By jasper77 in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 12-01-2005, 09:26 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •