I’m currently storing dates in my MYSQL database as a PHP timestamp (integer field). However, if I retrieve it from the database and use the PHP date function, would it display the correct time based on the client’s time zone.
For example, I display a PHP timestamp 1310674625 (pulled from DB) which is Jul 14 2011 22:17:05 in Eastern Time. So if I display the timestamp in PHP with the code below, would a person viewing the webpage in the Pacific Time Zone see Jul 14 2011 19:17:05 instead?
echo date('M d Y H:i:s', 1310674625);
No. The date will be displayed according to the server’s time and timezone, not the user’s.
You can offer an option on your site to allow the user provide his/her timezone (or attempt to use geolocation based on the IP) and adjust the output according.
According to this post, reliably determining the user’s timezone may not be possible, so for best results, you may need to get input from the user.
EDIT (Based on the request for more information in the comments)
If you need to output the selected timezone, you can use one of the following options:
See the date manual page for more information.
EDIT 2:
To “print the date to a specified timezone” you will need to:
time())date().