Function : Converts GMT time to a localized value

0saves

Converts GMT time to a localized value

This function takes  a Unix timestamp (in GMT) as input, and returns the local value based on the timezone and DST setting submitted.


/**
 * Converts GMT time to a localized value
 *
 * Takes a Unix timestamp (in GMT) as input, and returns
 * at the local value based on the timezone and DST setting
 * submitted
 *
 * @param    integer Unix timestamp = $time
 * @param    string    timezone = $timezone
 * @param    bool    whether DST is active = $dst
 * @return    integer
 */
if ( ! function_exists('gmt_to_local'))
{
 function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE)
 {
 if ($time == '')
 {
 return now();
 }

 $time += timezones($timezone) * 3600;

 if ($dst == TRUE)
 {
 $time += 3600;
 }

 return $time;
 }
}

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Related Posts

About the Author: Abhishek Sanghvi

Hi Friends, my name is Abhishek Sanghvi and I am the founder of this “open source script” site MYPHPSCRIPTZ. I have been learning and practising PHP from the last 3 years. You could always contact me if you wish to have some code for your need. I would surely try and solve them for you at abhishek(at)myphpscriptz(dot)com

4 Comments + Add Comment

Leave a comment


eight + = fifteen

CommentLuv badge