News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Live Server Time script (SSI or PHP)

Started by ganeshbala, Apr 15, 2009, 02:48 PM

Previous topic - Next topic

ganeshbala

Live Server Time script (SSI or PHP)

<script type="text/javascript">

// Current Server Time script (SSI or PHP)- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400  free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// This notice must stay intact for use.

//Depending on whether your page supports SSI (.shtml) or PHP (.php), UNCOMMENT the line below your page supports and COMMENT the one it does not:
//Default is that SSI method is uncommented, and PHP is commented:

var currenttime = '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' //SSI method of getting server date
//var currenttime = '<? print date("F d, Y H:i:s", time())?>' //PHP method of getting server date

///////////Stop editting here/////////////////////////////////

var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
var serverdate=new Date(currenttime)

function padlength(what){
var output=(what.toString().length==1)? "0" what : what
return output
}

function displaytime(){
serverdate.setSeconds(serverdate.getSeconds() 1)
var datestring=montharray[serverdate.getMonth()] " " padlength(serverdate.getDate()) ", " serverdate.getFullYear()
var timestring=padlength(serverdate.getHours()) ":" padlength(serverdate.getMinutes()) ":" padlength(serverdate.getSeconds())
document.getElementById("servertime").innerHTML=datestring " " timestring
}

window.onload=function(){
setInterval("displaytime()", 1000)
}

</script>

<p><b>Current Server Time:</b> <span id="servertime"></span></p>

<p style="font: normal 11px Arial">This free script provided by<br />
<a href="http://www.javascriptkit.com">JavaScript Kit</a></p>


Description: This unique JavaScript allows you to display the server time of your website, live! Using either SSI or PHP (depending on which one your page supports) to first retrieve the current static server time, the script then updates it every second for display. Cool!

Note that in order to use this script, the page the script is on must either be SSI or php enabled (ie: .shtml or .php). Refer to the comment inside script to uncomment/comment a specific line, depending on the method you're using.

Current server time: April 15, 2009 05:15:21

Directions: Simply insert the below into the <body> section of the page that will show the time. Be sure to read the comment on which line to comment and uncomment following it, based on whether your page is SSI or PHP enabled.


Source javascript kit