Skip to content
Advertisement

How to display localized time, based on a visitor’s location?

We’re developing a website, that will be used from people all over the world. There’s a chat section in the website and we want the messages to appear with a timestamp. I’m storing in a database a timestamp for each message.

What is the way to show the right time for each message to visitor, based on his local time.

I don’t want to ask the user for his timezone. Is there a way to do this, using only PHP? If not – what is the way to show the current time, based on the visitors’ current time, using javascript?

Advertisement

Answer

You can make a educated guess on the users timezone with geo IP

http://php.net/manual/en/book.geoip.php

Or you can use javascript:

http://www.onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement