how can i get the time of the client side?
when i use date(). it returns server's time
thanks
how can i get the time of the client side?
when i use date(). it returns server's time
thanks
PHP is server side only as far as i know.
You maybe want to use JavaScript.
As PHP runs on the server-side, you cannot access the client-side time from PHP : PHP doesn't know much about the browser -- and you can have PHP scripts that run without being called from a browser.
But you could get it from Javascript (which is executed on the client-side), and, then, pass it to PHP via an Ajax request, for example.
And here are a couple of questions+answers that might help you getting started :
As mentioned by everyone PHP only displays server side time.
For client side, you would need Javascript, something like the following should do the trick.
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
if (minutes < 10)
minutes = "0" + minutes
document.write("<b>" + hours + ":" + minutes + " " + "</b>")
And if you want the AM/PM suffix, something like the following should work:
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
var suffix = "AM";
if (hours >= 12) {
suffix = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
if (minutes < 10)
minutes = "0" + minutes
document.write("<b>" + hours + ":" + minutes + " " + suffix + "</b>")
Here is a list of additional JS Date and Time functions you could mess around with: http://www.quackit.com/javascript/javascript_date_and_time_functions.cfm
Here's a "PHP" solution:
echo '<script type="text/javascript">
var x = new Date()
document.write(x)
</script>';
You could possibly use Geolocation by IP Address to work out which country the user is in, and then use that.
But using Javascript or letting the user choose a Timezone will probably be better.