Change Time Zone or Server Clock for your Websites

For webmasters who have their websites hosted overseas, they may want to change the Server Clock or Time Zone to their own country or area other than the physical server which is running their websites. For example, if you live in Europe/Lisbon, however you have a blog hosted in America/Los_Angeles. How can you offset the default time zone or server clock?

If your website is running on PHP + Apache server, you can override the Time zone or server clock for your location instead of the server time zone by either adding a code line to the .htaccess file or your php script.

Change Time Zone in .htaccess File

Simply add the line in following format to the .htaccess file:

SetEnv TZ ‘location’

For example,

SetEnv TZ America/Los_Angeles

Or

SetEnv TZ Europe/Lisbon

Many php hosting service providers should allow you to create or customize this .htaccess file. Normally the .htaccess file can be found under /public_html/ (or a subdirectory if for a subdomain or addon domain).

Change Time Zone with PHP Script

You can change the time zone being displayed by using a PHP script. Here are two sample codes:

<?php
putenv(“TZ=Europe/Berlin”);
?>

or

<?php
date_default_timezone_set(“Europe/Luxembourg”);
?>

A list of supported Timezones can be found here:

http://www.php.net/manual/en/timezones.php

One comment

Leave a Reply