什么是使用strtotime的问题函数jgmdate

时间:2011-09-15 15:21:13

标签: php codeigniter

我使用codeigniter。对于函数strtotime(Jalali日期),Wy不工作jgmdate

此代码没有输出。(如果我使用if($ date_go == $ expiration_date)它有输出,如果两个日期不相等)

我使用这个助手:Sun Calendar Helper-Hijri Shamsi

$expiration_date = strtotime(jgmdate("Y/m/j")); // ==> 1390/06/24
        $string = '';
        foreach ($query->result() as $row)
                        {
            $date_go = strtotime($row->date_go;) // ==> 1390/07/05          
            if($date_go > $expiration_date){
                $string .= '<option>'.$row->name.'</option>';
            }
                        }
        $output = $string;
帮助太阳日历中的

函数jgmdate:

function jgmdate($type,$maket="now")
{
    //set 1 if you want translate number to farsi or if you don't like set 0
    $transnumber=0;
    ///chosse your timezone
    $TZhours=3;
    $TZminute=30;
    $need="";
    $result1="";
    $result="";
    if($maket=="now"){
        $year=gmdate("Y");
        $month=gmdate("m");
        $day=gmdate("d");
        list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
        $maket=mktime(gmdate("H")+$TZhours,gmdate("i")+$TZminute,gmdate("s"),gmdate("m"),gmdate("d"),gmdate("Y"));
    }else{
        //$maket=0;
        $maket+=$TZhours*3600+$TZminute*60;
        $gmdate=gmdate("Y-m-d",$maket);
        list( $year, $month, $day ) = preg_split ( '/-/', $gmdate );

        list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
        }

    $need= $maket;
    $year=gmdate("Y",$need);
    $month=gmdate("m",$need);
    $day=gmdate("d",$need);
    $i=0;
    $subtype="";
    $subtypetemp="";
    list( $jyear, $jmonth, $jday ) = gregorian_to_jalali($year, $month, $day);
    while($i<strlen($type))
    {
        $subtype=substr($type,$i,1);
        if($subtypetemp=="\\")
        {
            $result.=$subtype;
            $i++;
            continue;
        }

        switch ($subtype)
        {

            case "A":
                $result1=gmdate("a",$need);
                if($result1=="pm") $result.= "&#1576;&#1593;&#1583;&#1575;&#1586;&#1592;&#1607;&#1585;";
                else $result.="&#1602;&#1576;&#1604;&#8207;&#1575;&#1586;&#1592;&#1607;&#1585;";
                break;

            case "a":
                $result1=gmdate("a",$need);
                if($result1=="pm") $result.= "&#1576;&#46;&#1592;";
                else $result.="&#1602;&#46;&#1592;";
                break;
            case "d":
                if($jday<10)$result1="0".$jday;
                else    $result1=$jday;
                if($transnumber==1) $result.=Convertnumber2farsi($result1);
                else $result.=$result1;
                break;
            case "D":
                $result1=gmdate("D",$need);
                if($result1=="Thu") $result1="&#1662;";
                else if($result1=="Sat") $result1="&#1588;";
                else if($result1=="Sun") $result1="&#1609;";
                else if($result1=="Mon") $result1="&#1583;";
                else if($result1=="Tue") $result1="&#1587;";
                else if($result1=="Wed") $result1="&#1670;";
                else if($result1=="Thu") $result1="&#1662;";
                else if($result1=="Fri") $result1="&#1580;";
                $result.=$result1;
                break;
            case"F":
                $result.=monthname($jmonth);
                break;
            case "g":
                $result1=gmdate("g",$need);
                if($transnumber==1) $result.=Convertnumber2farsi($result1);
                else $result.=$result1;
                break;
            case "G":
                $result1=gmdate("G",$need);
                if($transnumber==1) $result.=Convertnumber2farsi($result1);
                else $result.=$result1;
                break;
                case "h":
                $result1=gmdate("h",$need);
                if($transnumber==1) $result.=Convertnumber2farsi($result1);
                else $result.=$result1;
                break;
            case "H":
                $result1=gmdate("H",$need);
                if($transnumber==1) $result.=Convertnumber2farsi($result1);
                else $result.=$result1;
                break;
            case "i":
                $result1=gmdate("i",$need);
                if($transnumber==1) $result.=Convertnumber2farsi($result1);
                else $result.=$result1;
                break;
            case "j":
                $result1=$jday;
                if($transnumber==1) $result.=Convertnumber2farsi($result1);
                else $result.=$result1;
                break;
            case "l":
                $result1=gmdate("l",$need);
                if($result1=="Saturday") $result1="&#1588;&#1606;&#1576;&#1607;";
                else if($result1=="Sunday") $result1="&#1610;&#1603;&#1588;&#1606;&#1576;&#1607;";
                else if($result1=="Monday") $result1="&#1583;&#1608;&#1588;&#1606;&#1576;&#1607;";
                else if($result1=="Tuesday") $result1="&#1587;&#1607;&#32;&#1588;&#1606;&#1576;&#1607;";
                else if($result1=="Wednesday") $result1="&#1670;&#1607;&#1575;&#1585;&#1588;&#1606;&#1576;&#1607;";
                else if($result1=="Thursday") $result1="&#1662;&#1606;&#1580;&#1588;&#1606;&#1576;&#1607;";
                else if($result1=="Friday") $result1="&#1580;&#1605;&#1593;&#1607;";
                $result.=$result1;
                break;
            case "m":
                if($jmonth<10) $result1="0".$jmonth;
                else    $result1=$jmonth;
                if($transnumber==1) $result.=Convertnumber2farsi($result1);
                else $result.=$result1;
                break;
            case "M":
                $result.=short_monthname($jmonth);
                break;
            case "n":
                $result1=$jmonth;
                if($transnumber==1) $result.=Convertnumber2farsi($result1);
                else $result.=$result1;
                break;
            case "s":
                $result1=gmdate("s",$need);
                if($transnumber==1) $result.=Convertnumber2farsi($result1);
                else $result.=$result1;
                break;
            case "S":
                $result.="&#1575;&#1605;";
                break;
            case "t":
                $result.=lastday ($month,$day,$year);
                break;
            case "w":
                $result1=gmdate("w",$need);
                if($transnumber==1) $result.=Convertnumber2farsi($result1);
                else $result.=$result1;
                break;
            case "y":
                $result1=substr($jyear,2,4);
                if($transnumber==1) $result.=Convertnumber2farsi($result1);
                else $result.=$result1;
                break;
            case "Y":
                $result1=$jyear;
                if($transnumber==1) $result.=Convertnumber2farsi($result1);
                else $result.=$result1;
                break;      
            case "U" :
                $result.=mktime();
                break;
            case "Z" :
                $result.=days_of_year($jmonth,$jday,$jyear);
                break;
            case "L" :
                list( $tmp_year, $tmp_month, $tmp_day ) = jalali_to_gregorian(1384, 12, 1);
                echo $tmp_day;
                /*if(lastday($tmp_month,$tmp_day,$tmp_year)=="31")
                    $result.="1";
                else 
                    $result.="0";
                    */
                break;
            default:
                $result.=$subtype;
        }
        $subtypetemp=substr($type,$i,1);
    $i++;
    }
    return $result;
}

EDITE:

$query = $this->db->query("SELECT * FROM table ORDER BY id desc");

    if($query->num_rows()==0){
        $data['output'] = 'There is not row';
    }else{

        $expiration_date = strtotime(date("Y/m/d")); // NOW
        $string = '';
        foreach ($query->result() as $row){
        list($j_y, $j_m, $j_d) = explode('/',$row->date_go);
        $date_go = strtotime(jalali_to_gregorian($j_y, $j_m, $j_d)); //Line 20
        if($date_go > $expiration_date){
            $string .= '<option>'.$row->name.'</option>';
        }
        }
        $data['output'] = $string;

    $this -> load -> view('ViewPage', $data); //This is line 28

1 个答案:

答案 0 :(得分:3)

尝试:

$expiration_date = strtotime(date("Y/m/d")); // NOW
$string = '';
foreach ($query->result() as $row){
    list($j_y, $j_m, $j_d) = explode('/',$row->date_go);
    $gt= jalali_to_gregorian($j_y, $j_m, $j_d);
    list($y, $m, $d) = $gt;

    $date_go = strtotime(date("$y/$m/$d"));
    if($date_go > $expiration_date){
        $string .= '<option>'.$row->name.'</option>';
    }
}
$output = $string;