I want to display the time and date on my website in real-time, and so far I got the time to display, but it's static server time. How do I get it so that it actually scrolls by without the visitor having to refresh the page?
This is what I have so far:
//////////////
//index.php //
//////////////
<?php
///////////////////////////////
require_once('datetime.php');// datetime.php IS SPELLED OUT FURTHER DOWN THE PAGE--I'M NOT EVEN SURE IF 'require_once' IS
/////////////////////////////// THE CORRECT THING TO PUT HERE
echo "<!DOCTYPE html>
<html>
<head>
/////////////////////////////////////////////////////////////////////////////////////
<script src='//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'></script>//
//
<script src='scripts.js'></script> //SHOULD THESE SCRIPT REFERENCES
//BE HERE? ARE THEY THE RIGHT ONES?
<script type='text/javascript' src='jquery-1.4.1.min.js'></script> //DO I NEED MORE TO MAKE IT WORK?
/////////////////////////////////////////////////////////////////////////////////////
</head>
<body>
/////////////////////////////////////////
<script type='text/javascript'> //
$(document).ready(function() { //
function update() { //
$.ajax({ //
type: 'POST', //
url: 'datetime.php', //
timeout: 1000, //
success: function(data) { // NOT SURE WHERE THIS SECTION SHOULD BE PLACED
$('#timer').html(data); // ANYWHERE IN THE BODY? AFTER THE OPENING BODY TAG?
window.setTimeout(update, 1000); // BEFORE THE CLOSING BODY TAG? IN THE HEAD?
}, //
}); //
} //
}); //
//
</script>"; //
/////////////////////////////////////////
echo "<div id='timer'>";//
echo $msg; // HERE'S WHERE THE TIME IS DISPLAYED, BUT IT'S JUST STATIC SERVER TIME
echo "</div>"; // AT THE STROKE OF MIDNIGHT I WANT THE DAY TO SCROLL OVER WITHOUT VISITOR HAVING TO REFRESH
////////////////////////// I WANT IT TO APPEAR JUST LIKE YOU'RE LOOKING AT A DIGITAL WATCH
echo "</body>";
echo "</html>;
?>
/////////////////
//datetime.php //
/////////////////
<?php
$mlscmsg = date('T');
$secmsg = date('s');
$minmsg = date('i');
$datemsg = date('j');
$yearmsg = date('Y');
$monthmsg = date('F');
$daymsg = date('l');
$timemsg = date('g');
$ampmmsg = date('A');
$msg = "<strong>You were here on " . $daymsg . ", " . $monthmsg . " " . $datemsg . ", " . $yearmsg . " at " . $timemsg . ":" . $minmsg . ":" . $secmsg . " " . $ampmmsg . " " . $mlscmsg . "</strong>";
?>
THE CLOCK OUTPUT CAN BE SEEN ON http://funkyfaucet.tk
if anyone knows how to make this appear in the browser as an actual clock, with seconds, minutes, days, etc. scrolling in real time, please contact "funkmaster" on peerbet.org