How to show GMT Time based upon country in php

I want to show GMT Timebased upon country. If suppose, some user from india, register into my application i should append GMT time as GMT +5 into my database. If suppose, some other user from france, register into my application i should append GMT time as GMT +1 into my database.


If you want to do it in PHP, you'll need geolocation for this. There are two ways: the homebrew way, or the API way. Depending on the resolution you would like, things might differ. Bear in mind that this will not magically detect proxies. The trade-offs are between efficiency and housekeeping.


Pick up a geolocation DB and query it for the IP subset, which will give you the country. Keep a list of timezones for countries. It's a pain, which is why I'm not going to give code for it.


This one is trivial:

  $geoloc = file_get_contents("<API KEY>&ip=".$_SERVER['REMOTE_ADDR']);
  if ($geoloc && ($r = json_decode($geoloc)) !== false) {
    // Your timezone is in $r->timeZone in the format "+/-i:ii"

You'll need an API key for ipinfodb, which you can get at this address:

Sometimes, there's not a server-based/PHP method for getting local time.

You have to get it from the client via Javascript. Google bitbucket timezone detect and use it to set a local_timezone cookie that you can read from PHP and set via date_default_timezone_set()

//get the client ip and assign it to variable
//if you using localhost you can check using follow variable
//$IP = '';
//pass the ip as a parameter for follow URL it will return the country
$country = file_get_contents(''.$IP);
//show the country
echo $country

Further more, here is the link which will help you to get the GTM timezone...

How do i get the gmt time in php

You need to implement your own logic, for example, get the client's time and deduct it from GTM-0, what you will get will be the GTM (hours).. Hope you get what I want to say..

Hope it helps.

Need Your Help

Is there an alternative to code render blocks?

c# .net webforms

When I want to write the result of a function as-is onto a masterpage or aspx page without a span container created by a label, I use a code render block. It works, and it does the job reliably.

SQL Reporting count of parameter in a column

sql count ssrs-2008

I am working in SSRS 3.0 with a SQL table including the following fields:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.