. . .

How to set timezone at application level and user login level using PHP

Published: May 27, 2013

To set timezone in php at user level, you have to use the function date_default_timezone_set().

This function is available in version 5 and later of PHP

 

<?php
date_default_timezone_set('America/Los_Angeles');
// To see a list of all supported time zones please go to : http://www.php.net/manual/en/timezones.php
$script_tz = date_default_timezone_get();
if (strcmp($script_tz, ini_get('date.timezone'))){        //compares current time zone with value script

 

Since PHP 5.1.0 (when the date/time functions were rewritten), every call to a date/time function will generate a E_NOTICE if the timezone isn't valid, and/or aE_WARNING message if using the system settings or the TZ environment variable.

 

 

  echo 'Script timezone differs from ini-set timezone.';
} else {
    echo 'Script timezone and ini-set timezone match.';
}
?>

Instead of using this function you can also use the php.ini to set the default time zone, for more information on setting the default time zone through php.ini go to : http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone

 

to set time zone at application level you have to go to wamp, then go to Home » Service Configuration » PHP Configuration Editor, and clicking the Advanced Mode radio button. The setting to change is date.timezone. This applies to all sites on the server unless overridden by custom php.ini files.

 

 

Don't forget to share this post

    Let's Build Digital Excellence Together


    • Cost Efficient Solutions.
    • Minimal Timelines.
    • Effective Communication.
    • High Quality Standards.
    • Lifetime Support.
    • Transparent Execution.
    • 24/7 Availability.
    • Scalable Teams.

    Join Our 200+ Happy Clients Across Globe


    Free Consultation.

      Do you need help in strategy, innovation or growth of your startup/business? Experts from our team will get in touch with you.

      Please do not post jobs/internships inquiries here.