I want to display the current date and time of the users time zone in the format ("Y-m-d H:i:s") PHP
Translations
Englishالعربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
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 Ayush Saraf (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 Feida Kila
Find More Answers