i want to get the visitor local time and date using php. I am try different method but failed. i am using strftime('%c');
Asked
Active
Viewed 48 times
1
-
why you use `strftime('%c')`? – Murad Hasan May 08 '16 at 09:19
-
[strftime](http://php.net/manual/en/function.strftime.php): `%C` -Two digit representation of the century (year divided by 100, truncated to an integer). – Murad Hasan May 08 '16 at 09:21
-
@FrayneKonok But the OP has used '%c' Preferred date and time stamp based on locale – vascowhite May 08 '16 at 09:23
-
Possible duplicate of [How to get client's timezone?](http://stackoverflow.com/questions/1905397/how-to-get-clients-timezone) – cb0 May 08 '16 at 09:24
-
Possible duplicate of [Determine a User's Timezone](http://stackoverflow.com/questions/13/determine-a-users-timezone) – vascowhite May 08 '16 at 09:26
2 Answers
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.
-
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
-
1This 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