dabluesfreaks Posted December 12, 2011 Share Posted December 12, 2011 is there anyway to make the following displayed time ticking?? please help me out guys !! <?php date_default_timezone_set('America/New_York'); echo date('D,F j, Y, h:i:s A'); ?> Link to comment https://forums.phpfreaks.com/topic/252982-how-can-i-make-this-clock-ticking-on-my-websitewithout-refreshing-the-page/ Share on other sites More sharing options...
kney Posted December 12, 2011 Share Posted December 12, 2011 Put this in your header <script type="text/javascript"> <!-- function updateClock ( ) { var currentTime = new Date ( ); var currentHours = currentTime.getHours ( ); var currentMinutes = currentTime.getMinutes ( ); var currentSeconds = currentTime.getSeconds ( ); // Pad the minutes and seconds with leading zeros, if required currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes; currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds; // Choose either "AM" or "PM" as appropriate var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM"; // Convert the hours component to 12-hour format if needed currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours; // Convert an hours component of "0" to "12" currentHours = ( currentHours == 0 ) ? 12 : currentHours; // Compose the string for display var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay; // Update the time display document.getElementById("clock").firstChild.nodeValue = currentTimeString; } // --> </script> In ur body you'll implement this <body onload="updateClock(); setInterval('updateClock()', 1000 )"> Link to comment https://forums.phpfreaks.com/topic/252982-how-can-i-make-this-clock-ticking-on-my-websitewithout-refreshing-the-page/#findComment-1297026 Share on other sites More sharing options...
dabluesfreaks Posted December 12, 2011 Author Share Posted December 12, 2011 thank you kney for your quick reply..but i am wondering who can i get the specific date and time of the country (city) rather than system date and time... is there any way to get specific date and time like in php date_default_timezone_set('America/New_York'); Link to comment https://forums.phpfreaks.com/topic/252982-how-can-i-make-this-clock-ticking-on-my-websitewithout-refreshing-the-page/#findComment-1297028 Share on other sites More sharing options...
kney Posted December 12, 2011 Share Posted December 12, 2011 <script language="JavaScript"> // function to calculate local time // in a different city // given the city's UTC offset function calcTime(city, offset) { // create Date object for current location d = new Date(); // convert to msec // add local time zone offset // get UTC time in msec utc = d.getTime() + (d.getTimezoneOffset() * 60000); // create new Date object for different city // using supplied offset nd = new Date(utc + (3600000*offset)); // return time as a string return nd.toLocaleString(); } // get New York time alert(calcTime('New York', '-5')); </script> } // get Bombay time alert(calcTime('Bombay', '+5.5')); Link to comment https://forums.phpfreaks.com/topic/252982-how-can-i-make-this-clock-ticking-on-my-websitewithout-refreshing-the-page/#findComment-1297030 Share on other sites More sharing options...
dabluesfreaks Posted December 12, 2011 Author Share Posted December 12, 2011 i am really counting on you kney...please help me out !!! Link to comment https://forums.phpfreaks.com/topic/252982-how-can-i-make-this-clock-ticking-on-my-websitewithout-refreshing-the-page/#findComment-1297032 Share on other sites More sharing options...
kney Posted December 12, 2011 Share Posted December 12, 2011 changed my last post Link to comment https://forums.phpfreaks.com/topic/252982-how-can-i-make-this-clock-ticking-on-my-websitewithout-refreshing-the-page/#findComment-1297033 Share on other sites More sharing options...
dabluesfreaks Posted December 12, 2011 Author Share Posted December 12, 2011 thank you sooooooooooooooo much kney Link to comment https://forums.phpfreaks.com/topic/252982-how-can-i-make-this-clock-ticking-on-my-websitewithout-refreshing-the-page/#findComment-1297034 Share on other sites More sharing options...
kney Posted December 12, 2011 Share Posted December 12, 2011 Just saw I added too much this wasn't supposed to be under the rest anymore.. and no problem } // get Bombay time alert(calcTime('Bombay', '+5.5')); Link to comment https://forums.phpfreaks.com/topic/252982-how-can-i-make-this-clock-ticking-on-my-websitewithout-refreshing-the-page/#findComment-1297036 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.