开发者

How can i get current date based on the visitor's country?

I'm hosting my site in US and my site lists events based on time and holidays and birthdays based on dates..

I'm using php and mysql

when someone visits my site from india the date that will be shown on the site will be a day lesser..

How can 开发者_开发问答i get the change the date and time based upon the visitor's country?


You can get their timezone offset with JavaScript.


@Ishmaeel said:

The most popular (==standard?) way of determining the time zone I've seen around is simply asking the user ximself. If your website requires subscription, this could be saved in the users' profile data. For anon users, the dates could be displayed as UTC or GMT or some such.

I'm not trying to be a smart-alec. It's just that sometimes some problems have finer solutions outside of any programming context.

Determine a User's Timezone


  1. Get the IP of the visitor by using this:
    $visitorIP = $_SERVER['REMOTE_ADDR'];

  2. Map it to country / city. There are many IP to country database available. I prefer MaxMind GeoIP Country Database and MaxMind GeoIP City Database.

  3. Convert the timezone to that country / city.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜