I need to know what should I do to show event time (stored in mysql) according viewer's local time.

I have stored time in two format (one simple 12:30; and another in timestamp format). The timings are of future and stored as GMT.

Now, I would like to show time of event according to the viewer's location. Suppose Visitor is from India than Time should be in IST (GMT + 05:30 Hours). How its possible ?


I have no idea how to fetch data from mysql and convert it to show offset time.

I might be wrong, about what I am telling. It should be like this - http://www.cricinfo.com/england-v-australia-2010/content/series/426337.html?template=fixtures

What I see as of now is this http://img293.imageshack.us/img293/4341/75715530.png

What I see is like below. When you see the url, it will time according to your ip (or zone no idea)

I think I might also need to use http://www.maxmind.com/app/free

What you need is to use javascript rather than php.
it will work alot better.
but here is php code

<?php 
// 
// File: gmttime.php 
// 
// Description: 
//    Implements the gmttime function if missing from the PHP distribution 
// 

// Verifies that the function isn't already implemented 
if (function_exists(gmttime)) 
    return; 

// 
// Function: gmttime 
// 
// Description: 
//   Returns an array indexed as by the localtime() function: 
//   - 0 or tm_sec: Seconds 
//   - 1 or tm_min: Minutes 
//   - 2 or tm_hour: Hour 
//   - 3 or tm_mday: Day of the month 
//   - 4 or tm_mon: Month of the year 
//   - 5 or tm_year: Years since 1900 
//   - 6 or tm_wday: Day of the week 
//   - 7 or tm_yday: Day of the year 
//   - 8 or tm_isdst: Is daylight saving time in effect 
//   - tm_fyear: Full year (only available with associative array) 
// 
// Arguments: 
//   - Timestamp 
//   - Boolean (for associative indexing: 0 = off, 1 = on) 
// 
// Returns: 
//   An array on success, 
//   false on failure. 
// 
function gmttime($dTimestamp = '', $bAssoc = 0) { 
    // Evaluate how much difference there is between local and GTM/UTC 
    // Don't forget to correct for daylight saving time... 
    $aNow = localtime(); 
    $iDelta = gmmktime(1, 1, 1, 1, 1, 1970, $aNow[8]) - mktime(1, 1, 1, 1, 1, 1970, $aNow[8]); 

    if (!$bAssoc) { 
        if ($dTimestamp == '') { 
            return localtime(time() - $iDelta, 0); 
        } else { 
            return localtime($dTimestamp - $iDelta, 0); 
        } 
    } else { 
        // For associative array, add full year index 
        if ($dTimestamp == '') { 
            $aGMTTime = localtime(time() - $iDelta, 1); 
        } else { 
            $aGMTTime = localtime($dTimestamp - $iDelta, 1); 
        } 
        $aGMTTime['tm_fyear'] = $aGMTTime['tm_year'] + 1900; 
        return $aGMTTime; 
    } // End [IF] return associative array? 
} // End [FUNCTION] gmttime 
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.