Last week while I was working on an auction management project, I faced a time zone problem. The problem was that my web server was in USA and I have to manage online auction in India. So when I gave an auction its Start Date and End Date, it stored Indian time in the database, which is almost 12 hrs later than the Server time (Central Time USA). So when a user is looking for current active auction, they won’t be able to see the active auctions until the server time reaches the current Indian time, which will take 12 hrs more. So even though I created an auction starting from current Indian time, it will take 12 hours before any user can see this auction.

After searching for the solutions for quite some time, I came to know that if I change my server time zone to Indian time zone then my problem will be solved. So I again searched for the simplest way to change my server time zone to my desired time zone. After trying lots of codes, finally I came up with a one liner to solve this problem permanently and it was very easy.

You just have to write one line of code in the “.htaccess” file of your server. I wrote the following code for my .htacces file as I wanted my server time zone to match Indian time.

  • php_value date.timezone “Asia/Calcutta”

You can get your desired time zone by changing the “Asia/Calcutta” section. You can write your own time zone code, like “America/Denver” will give you Denver time in America. You can get full “List of Supported Time zones” from here.

You can also check if the time really changes or not on your server, just create a .php file on your server with this code

?php print date (‘D, d M Y H:i:s T’); ?

Access that file from the browser and you will see your server’s current time, verify it with your local time or the time you want your server time to be. In my case I got the following output on my browser for the Indian time zone.

  • Tue, 09 Nov 2010 15:26:07 IST

Latest posts by Soumyajit Dutta

  • Share/Bookmark