Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Current time code
#1
Hi, I'm building a new personal site and would like to show like "23:34" (not 11:34 pm, in the 24h format) in the bottom corner. I just need the code, I'll style and work around it myself. Preferably just hours and minutes, but if you have something with seconds as well it doesn't matter. Oh but if does actually includes seconds, please make it keep counting, you know.. like, it 'reloads' itself. So I don't have to refresh the page so the seconds change.

And obviously I mean a countup little clock.
I just really want the chars, not in a box or inside something else.. as simple as: "hours:minutes".
Reply
#2
This would probably get better results in the PHP section. If you agree, report your post and say, "Please move this to the PHP section" or otherwise ^^
Reply
#3
PHP would be best but there are a number of ways to do clocks. http://us2.php.net/manual/en/function.date.php That's where you'll find all the time and date functions of php so you can get to look how you want ;).
Reply
#4
Here you go

time.php
PHP Code:
<?php
print date("H:i:s");
?>

HTML file
javascript from : http://www.w3schools.com/Ajax/ajax_xmlhttprequest.asp
Code:
<html>
<head>

<script type="text/javascript">
function ajaxFunction()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Your browser does not support XMLHTTP!");
  }
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
  {
  document.getElementById("clock").innerHTML=xmlhttp.responseText;
  }
}
xmlhttp.open("GET","time.php",true);
xmlhttp.send(null);
}
</script>

</head>
<body onload="setInterval('ajaxFunction()', 1000);">

<div id="clock"></div>

</body>
</html>

If you want to output only Hours:Minutes just remove "Confused" from the date() function

PHP Code:
<?php
print date("H:i");
?>
Reply
#5
Thanks a bunch! Working just great. This is exactly what I wanted.
Again, thanks for your help, appreciated.
Reply
#6
(10-10-2009, 02:02 AM)faviouz Wrote: Thanks a bunch! Working just great. This is exactly what I wanted.
Again, thanks for your help, appreciated.

Thank you too. Roflmao
But the above code isn't working proberly in IE 5 and under.
Reply
#7
Lol which retard still uses ie5-
Quote:Who has two thumbs and doesn't give a crap.......Bob Kelso......Have we met?
[Image: BobKelso.jpg]
Reply
#8
(10-10-2009, 09:26 AM)Code King Wrote: Lol which retard still uses ie5-

lol I do/ well I don't but it is installed and I don't update it, just have no reason for that.
Reply
#9
(10-10-2009, 09:19 AM)NinjaGeek Wrote: Thank you too. Roflmao
But the above code isn't working proberly in IE 5 and under.

Actually a lot probably. In June 2008 it was good for 0,5% of all browser, that means 1 out o 200 people used internet explorer 5. There are no new statistics but you should still code with the face in mind that it is still used a lot.
Reply
#10
(10-10-2009, 10:13 AM)Legion Wrote: Actually a lot probably. In June 2008 it was good for 0,5% of all browser, that means 1 out o 200 people used internet explorer 5. There are no new statistics but you should still code with the face in mind that it is still used a lot.

Yes, because I'm worried about the .5% of people probably don't used a computer everyday.
http://www.w3schools.com/browsers/browsers_stats.asp

The W3C doesn't even keep track of it anymore. It's a dead browser.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)