Date Time Code

  Home arrow Date Time Code arrow convGmt
DATE TIME CODE

convGmt
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-11-05

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    This function is used when your have Overseas server, let's say your server is on GMT-7 and your Local time is on GMT +7, then you want your script time to use your Local (GMT+7) time.

    By : hermawan

    <?php
    /***********************************************
    * Snippet Name : convgmt *
    * Scripted By : Hermawan Haryanto *
    * Website : http://hermawan.com *
    * Email : hermawan@codewalkers.com *
    * License : GPL (General Public License) *
    ***********************************************/
    function convgmt ($cgmt) {
    $now = time();
    $sgmt = date("Z");
    $sgmt = $sgmt/3600;
    $diffh = $sgmt.$cgmt;
    if (is_int(strpos("-",$cgmt))) {
    $diffh = eval($diffh);
    } else {
    $diffh = $sgmt - $cgmt;
    }
    $realtime = $now - ($diffh*3600);
    return $realtime;
    }
    Header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    Header ('Last-Modified: '. gmdate("D, d M Y H:i:s") .' GMT');
    Header ('Cache-Control: no-store, no-cache, must-revalidate');
    Header ('Cache-Control: post-check=0, pre-check=0', false);
    Header ('Pragma: no-cache');
    $gmt = $_GET["gmt"];
    if (!isset($gmt)) $gmt = 7;
    print date("G:i:s l, F jS Y", convgmt($gmt));
    print "<br>";
    print date("g:i:s a l, F jS Y", convgmt($gmt));
    for ($i=-12;$i<=13;$i++) {
    if($i<0) {
    $j = substr($i,1,strlen($i));
    if (strlen($j)==1) $j = "0".$j;
    $j = "GMT-$j:00";
    $x = $i;
    } else {
    if (strlen($i)==1) {
    $j = "0".$i;
    } else {
    $j = $i;
    }
    $j = "GMT+$j:00";
    $x = "+".$i;
    }
    if (!isset($gmt)) {
    if ($i == 7) {
    $rtn .= "<option value='$x' selected>$j</option>";
    } else {
    $rtn .= "<option value='$x'>$j</option>";
    }
    } else {
    if ($i == $gmt) {
    $rtn .= "<option value='$x' selected>$j</option>";
    } else {
    $rtn .= "<option value='$x'>$j</option>";
    }
    }
    }
    ?>
    <form method="get">
    <select name="gmt"><?=$rtn;?></select> <input type="submit" value="Get My Time">
    </form>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Date Time Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    DATE TIME CODE ARTICLES

    - DaysInSpan.php
    - MySQLdateSpan.php
    - DateSpan.php
    - FutureDateFormEntry.php
    - Generate Time Option List for Select stateme...
    - Current Age Script (v2)
    - class for some mysql imitated time functions
    - Current Age Script, up to the last day
    - filemtime_remote
    - Page Generation Time Figure-Outer
    - convGMT v2
    - Benchmarker
    - Simple PHP Calendar
    - Display message according to hour of day
    - Display Date Function

    Developer Shed Affiliates

     



    © 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap