zgkhoo Posted October 29, 2007 Share Posted October 29, 2007 how to set the date n live time for my php site? which all php files of my site sharing the same live date/time and the live date/time appear in each php page.. thanks... Quote Link to comment Share on other sites More sharing options...
severndigital Posted October 29, 2007 Share Posted October 29, 2007 i use this script currently. it's javascript but when you call it, it will display the current server time. <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 = '<?php print date("F d, Y g: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 document.getElementById("serverdate").innerHTML=datestring document.getElementById("servertime").innerHTML=timestring } window.onload=function(){ setInterval("displaytime()", 1000) } </script> to call it use <span class="servertime" id="servertime"></span> that has served me well to date. Chris the pic attached is how I have it formatted for my use. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted October 29, 2007 Author Share Posted October 29, 2007 wow, cool.. thanks for ur sharing.. Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted October 30, 2007 Author Share Posted October 30, 2007 but how to get the date/time ...and pass these value to others...eg php variable. thanks.. Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted October 31, 2007 Author Share Posted October 31, 2007 *bump* Quote Link to comment Share on other sites More sharing options...
severndigital Posted November 2, 2007 Share Posted November 2, 2007 not sure what you mean?? for use with other what?? chris Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted November 5, 2007 Author Share Posted November 5, 2007 integrate with php...which passing the date/time value to php variable.. Quote Link to comment Share on other sites More sharing options...
Barand Posted November 5, 2007 Share Posted November 5, 2007 see http://www.phpfreaks.com/forums/index.php/topic,166229.msg731678.html#msg731678 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.