I want to display the current date and time of the users time zone in the format ("Y-m-d H:i:s") PHP

Possible Duplicate:
Timezone conversion in php
How to get client's timezone?

I want to display the current date and time of the users time zone in the format ("Y-m-d H:i:s") PHP

i used the simple function date("Y-m-d H:i:s"); and it did work but i want that viewers from different time zone should see the right time in their clock or time zone i want to match the time with their timezone how can i do that?

This question and answers originated from www.stackoverflow.com
Question by (11/15/2011 9:53:48 AM)

Answer

you could get the country where the request is being made from, get the timezone for that country, and apply the hours offset to your time

1) get the ip from the client  $_SERVER['REMOTE_ADDR']
2) get the country of that IP, using GeoIP library or a web service such as Maxmind
3) get the difference in hours (offset) for this country  (DateTime::getOffset  -  GeoIP::geoip_time_zone_by_country_and_region())
4) add/sustract the offset to your date with DateTime class (DateTime::add()) 
Answer by

Find More Answers
Related Topics  php  mysql  time  timestamp
Related Questions