国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

php實現比較_兩個字符串日期大小的方法

2019-11-02 15:28:37
字體:
來源:轉載
供稿:網友

   本文實例講述了php實現比較兩個字符串日期大小的方法。分享給大家供大家參考。具體如下:

  ?

1 2 3 4
罵人寶典[www.62-6.com/1/marenbaodian/]
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <?php function dateBDate($date1, $date2) { // 日期1是否大于日期2 $month1 = date("m", strtotime($date1)); $month2 = date("m", strtotime($date2)); $day1 = date("d", strtotime($date1)); $day2 = date("d", strtotime($date2)); $year1 = date("Y", strtotime($date1)); $year2 = date("Y", strtotime($date2)); $from = mktime(0, 0, 0, $month1, $day1, $year1); $to = mktime(0, 0, 0, $month2, $day2, $year2); if ($from > $to) { return true; } else { return false; } } ?> $date1 = "2009-10-13"; $date= mktime(0, 0, 0, date("m", strtotime($date1)), date("d", strtotime($date1)), date("Y", strtotime($date1)));

  最終取得一個日期的 Unix 時間戳$date=1255392000。

  很多時候做搜索的時候,搜索的時間不能大于當前日期,比較函數的寫法大致和上面一個函數相同,具體如下:

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 function dateBCurrent($date){ //日期是否大于當前日期 $currentDate=date("Y-m-d"); //獲取當前日期 $cYear=date("Y",strtotime($currentDate)); $cMonth=date("m",strtotime($currentDate)); $cDay=date("d",strtotime($currentDate)); $year=date("Y",strtotime($date)); $month=date("m",strtotime($date)); $day=date("d",strtotime($date)); $currentUnix=mktime(0,0,0,$cMonth,$cDay,$cYear); //當前日期的 Unix 時間戳 $dateUnix=mktime(0,0,0,$month,$day,$year); //待比較日期的 Unix 時間戳 if($dateUnix<=$currentUnix){ return true; }else{ return false; } }

  希望本文所述對大家的php程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武夷山市| 黎平县| 长垣县| 黄大仙区| 南漳县| 满洲里市| 法库县| 乡城县| 来安县| 巴林右旗| 临猗县| 凤城市| 南汇区| 日喀则市| 嘉义县| 青海省| 保亭| 紫金县| 黄陵县| 会宁县| 宁河县| 筠连县| 吉安市| 陇西县| 永定县| 满城县| 湘潭县| 柯坪县| 永兴县| 高唐县| 达日县| 乌恰县| 江源县| 通化市| 巴里| 迁西县| 普定县| 临武县| 太白县| 邵阳县| 贺兰县|