How To Change Your Webhost Server Time To Your Local Time.

Do you want to change your webhost server time to your local time? Are you finding it difficult to get it done? If yes, the solution is about to be revealed to you.

I remember while building my mobile wapsite i decided to add a clock to it, though i succeeded, but the time wasn’t in accordance to my country(NIGERIA) timezone which is GMT +1.

Since i was using a shared webhosting, i couldn’t change it because most shared webhosting have their server time time set to Central Standard Time.

After much trial, i finally got the solution which am about to share with you.

There are two ways known to me on how to achieve this, and am going to make it comprehensive as possible.

  1. Using a custom php Code
    This method is quite easy, all you need do it place any of the below code above a php date function.

    <?php
    putenv(“TZ=Africa/Lagos“);
    ?>

    OR

    <?php
    date_default_timezone_set (“Africa/Lagos“);
    ?>

    To make the server time changing to be accomplished, add any of the above code before a php date function, also change the Africa/Lagos to your own Country timezone.
    Example:

    <php
    date_default_timezone_set (“Africa/Lagos”);
    echo ‘<div class=”Border” align=”center”><b>’;
    print date(“h:i:s A – M j, Y”, time());
    echo ‘</b>’;
    ?>

    The php code above will display a clock in accordance with Africa/Lagos timezone.

    DEMO =>

    03:13:17 AM – Dec 3, 2012

    For a list of other supported timezone, click here to get your own country equivalent timezone.

  2. Using .htaccess file
    For me, this’s the easiest, efficient and recommended method on how to change your webhost server time.
    To do this, create a file and name it “.htaccess”, or you can edit the existing one. The .htaccess file belongs in /public_html/ folder or a subdirectory if for a subdomain or addon domain). Add the below line of code to it:

    SetEnv TZ Africa/Lagos

    .
    After that, whenever you add a clock(date&time) to your site, it automatically set to your country timezone.

Don’t forget to Change Africa/Lagos to your own country time zone.

Don’t miss out!
Subscribe to My Newsletter
Invalid email address