PDA

View Full Version : Display the date/time in various places on my website page



simonf
07-20-2017, 11:02 AM
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:

<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
<div class="privclock"></div>

rgds, Simon

coothead
07-20-2017, 03:10 PM
Hi there simonf,


does this help...



<!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

simonf
07-21-2017, 07:35 AM
Hi Coothead

Perfects mate...... many many thanks......... ;)

coothead
07-21-2017, 08:04 AM
No problem, you're very welcome. ;)


coothead