|
|
|
In this simple script you know your server time when your script is executed and also you get your current time stamp.
We use the PHP getdate() function which gives us an array containing the date information of the timestamp, or the current local time if no timestamp is given. We give time() as input to getdate() and get an array. That array is used to Calculate the server time. Also we calculate the local time with JavaScript.
more resources at : http://www.techgyan4u.com/
Please see code for details....
|
<br><br>
<span id="clock">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function getthedate(){
var mydate=new Date();
var hours=mydate.getHours();
var minutes=mydate.getMinutes();
var seconds=mydate.getSeconds();
var dn="AM";
if (hours>=12) dn="PM";
if (hours>12) hours=hours-12;
if (hours==0) hours=12;
if (minutes<=9) minutes="0"+minutes;
if (seconds<=9) seconds="0"+seconds;
var cdate="<b>Local Time</b> "+hours+":"+minutes+":"+seconds+" "+dn+"<BR>";
if (document.all)
document.all.clock.innerHTML=cdate;
else if (document.getElementById)
document.getElementById("clock").innerHTML=cdate;
else
document.write(cdate);
}
if (!document.all&&!document.getElementById) getthedate();
function goforit(){
if (document.all||document.getElementById) setInterval("getthedate()",1000);
}
window.onload=goforit;
// End -->
</SCRIPT>
</span>
<b>Server Time</b>
<?php
$thetimeis = getdate(time());
$thehour = $thetimeis['hours'];
$theminute = $thetimeis['minutes'];
$thesecond = $thetimeis['seconds'];
if($thehour > 12){
$thehour = $thehour - 12;
$dn = "PM";
}else{
$dn = "AM";
}
echo "$thehour: $theminute:$thesecond $dn";
?>
</p> | | |
|
| Local-to-user date and time display regardless of time zone or where the website's server is located Categories : PHP, Date Time, HTML and PHP, Java Script | | | Script loading time Categories : PHP, Beginner Guides, Date Time | | | How to Insert a Date Format Into MySQL from PHP Categories : PHP, Databases, MySQL, Date Time, Beginner Guides | | | Find the day of the week for any given year/month/day. Categories : PHP, Date Time, Data Validation, Algorithms, Beginner Guides | | | Newbie Notes #9 - Hyperlinking a post Categories : PHP, Java Script, HTML and PHP, Beginner Guides | | | Find if a year is leap. Categories : PHP, Date Time, Beginner Guides, Data Validation | | | Kewl Date Example Categories : PHP, HTML and PHP, Date Time, CSS, Beginner Guides | | | enhanced date picker with jcript checking for a dynamic date input Categories : PHP, Java Script, Date Time, Calendar, Arrays | | | Simple Javascript CSS Digital Clock Categories : Java Script, Date Time, CSS, Beginner Guides, Web Design | | | Easy alert box pop-up function Categories : PHP, Java Script, Beginner Guides | | | Date Validation using JavaScript. Intended to use it as checkdate() from PHP. Categories : Java Script, Date Time, PHP | | | Calendars to choose a range of dates , reservation events ... Categories : PHP, Calendar, Java Script, Date Time | | | PHP and javascript mouseover, mouseout, and mousedown events Categories : PHP, Java Script, Form Processing, Beginner Guides | | | Change the background color of a website daily dynamically using the php date function to get the current day of the week and depending on that day, set the background color for the web page. Categories : PHP, Date Time, Beginner Guides, Web Design | | | PHP Calendar Categories : PHP, Calendar, Date Time, Java Script, CSS | |
|
|