> 백엔드 개발 > PHP 튜토리얼 > PHP语句日期比较有关问题

PHP语句日期比较有关问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
풀어 주다: 2016-06-13 13:32:15
원래의
946명이 탐색했습니다.

PHP语句日期比较问题
如何在提交页面的时候比较本页面表单中两个日期startdate与enddate的大小,并做出判断。
有没有不管date是什么类型都能转换为可以比较大小的类型的日期函数?
用php语句写,本人不会js跟ajax,谢谢了!

------解决方案--------------------

PHP code
<?php function getTime($date)
{
$mon = array(
'Jan' => 1,
'Feb' => 2,
'Mar' => 3,
'Apr' => 4,
'May' => 5,
'June'=> 6,
'July'=> 7,
'Aug' => 8,
'Sept'=> 9,
'Oct' => 10,
'Nov' => 11,
'Dec' => 12
);

$m = substr($date, 0, strpos($date, '/'));
$good = str_replace($m, $mon[$m], $date);
// 返回整形的时间戳
return strtotime($good);
}
$date1 = "Apr/13/2012";
$date2 = "Apr/6/2012";
// 4月13号比4月16号大,结果为true
var_dump( getTime($date1) > getTime($date2) );
<br><font color="#e78608">------解决方案--------------------</font><br>
로그인 후 복사
C/C++ code
[User:liangdong Time:13:54:44 Path:~/php]$ php date.php 
2012/7/2[User:liangdong Time:13:54:46 Path:~/php]$ cat date.php 
<?php function str_to_time($str_date) {
        $mon_name = array(
                                "Jan", "Feb", "Mar",
                                "Apr", "May", "June",
                                "July", "Aug", "Sept",
                                "Oct", "Nov", "Dec"
                        );
        $mon_index = range(1, 12);

        $str_date = str_replace($mon_name, $mon_index, $str_date);
        return $str_date;
}

echo str_to_time("2012/July/2");

?>
<br><font color="#e78608">------解决方案--------------------</font><br>
로그인 후 복사
PHP code
cat: cat: No such file or directory
<?php function str_to_time($str_date) {
        $mon_name = array(
                                "Jan", "Feb", "Mar",
                                "Apr", "May", "June",
                                "July", "Aug", "Sept",
                                "Oct", "Nov", "Dec"
                        );
        $mon_index = range(1, 12);

        $str_date = str_replace($mon_name, $mon_index, $str_date);
        return @strtotime($str_date);
}

echo str_to_time("2012/July/2");

?> <div class="clear">
                 
              
              
        
            </div>
로그인 후 복사
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿