1

i want to get the visitor local time and date using php. I am try different method but failed. i am using strftime('%c');

2 Answers2

1

You can't, at least not reliably. The browser doesn't send its timezone to the server with each request.

You could look at the IP address the request came from, hope that it isn't a proxy, and use a GeoIP database to guess where the user is. From that you could extrapolate the timezone. Then you could convert between the server's timezone and the one you think the visitor is in.

Alternatively, you could use client-side JavaScript to get the timezone from the visitor's browser.

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Is it possible to get local time using [function.localtime](http://php.net/manual/en/function.localtime.php) – Murad Hasan May 08 '16 at 09:27
  • @FrayneKonok — That gets the **server's** localtime. The server knows nothing about the browser's localtime as the answer says. – Quentin May 08 '16 at 10:42
-1
<?php
echo "Created date is " . date("Y-m-d h:i:sa", $d);
?> 

try this it will give you the date and time use it in a hidden field to itget

Murad Hasan
  • 9,565
  • 2
  • 21
  • 42
Tolani
  • 68
  • 2
  • 1
    This will give the server date and time, not the client's local date and time as required in the question. – vascowhite May 08 '16 at 09:24