Support Forums
Current time code - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21)
+---- Thread: Current time code (/showthread.php?tid=934)

Pages: 1 2


Current time code - faviouz - 10-09-2009

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".


RE: Current time code - Elektrisk - 10-09-2009

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


RE: Current time code - Alex - 10-09-2009

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 ;).


RE: Current time code - Gaijin - 10-09-2009

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");
?>



RE: Current time code - faviouz - 10-10-2009

Thanks a bunch! Working just great. This is exactly what I wanted.
Again, thanks for your help, appreciated.


RE: Current time code - Gaijin - 10-10-2009

(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.


RE: Current time code - Code King - 10-10-2009

Lol which retard still uses ie5-


RE: Current time code - Gaijin - 10-10-2009

(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.


RE: Current time code - Legion - 10-10-2009

(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.


RE: Current time code - Alex - 10-10-2009

(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.