two timezone in php

Discussion in 'PHP' started by hiteshb, Oct 6, 2009.

  1. #1
    I have one field where I enter GMT time of the upcoming match. Now I want to show IST time too along with GMT. i.e. I want to have two table td with one gmt and other IST. What should I put to make sure, it shows two different time zones.
     
    hiteshb, Oct 6, 2009 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    To convert a timezone to your server localzone, use:

    
    // Converts from GMT to the server timezone
    echo date('Y-m-d H:i', strtotime('2008-10-09 08:55 GMT'));
    
    PHP:
    To specifically convert from GMT to IST:

    
    $current_date = date("Y-m-d H:i:s",
    mktime(date("H")+5.5,date("i"),date("s"),date("m"),date("d"),date("Y")));
    echo $current_date;
    
    PHP:
    Second one not tested.
     
    ThePHPMaster, Oct 7, 2009 IP
  3. mdrobiul

    mdrobiul Peon

    Messages:
    186
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    // SELECT TIME ZONE
    $sign = "+"; // Whichever direction from GMT to your timezone.
    $h = "6"; // Hour for time zone goes here e.g. +8 or -4, just remove the + or -
    $dst = "false"; // Just insert "true" if your location uses daylight savings time or "false" if it does not
    // DETECT AND ADJUST FOR DAYLIGHT SAVINGS TIME
    if ($dst) {
    $daylight_saving = date('I');
    if ($daylight_saving){
    if ($sign == "-"){ $h=$h-1; }
    else { $h=$h+1; }
    }
    }
    // FIND DIFFERENCE FROM GMT
    $hm = $h * 60;
    $ms = $hm * 60;
    // SET CURRENT TIME
    if ($sign == "-"){ $timestamp = time()-($ms); }
    else { $timestamp = time()+($ms); }
    // SAMPLE OUTPUT
    $gmdate = gmdate("l, dS F Y, g:i:s A", $timestamp);
    echo "<td class='tpmiddle'>".$gmdate."</td>";
     
    mdrobiul, Oct 7, 2009 IP