zoukankan      html  css  js  c++  java
  • php判断该月有多少天


    1. /**
    2.  * 判断某年的某月有多少天
    3.  * @return [type] [description]
    4.  */
    5. function daysInmonth($year='',$month=''){
    6.      if(empty($year)) $year = date('Y');
    7.      if(empty($month)) $month = date('m');
    8.      if (in_array($month, array(1, 3, 5, 7, 8, '01', '03', '05', '07', '08', 10, 12))) { 
    9.             $text = '31';         //月大
    10. }elseif ($month == 2 || $month == '02'){ 
    11. if ( ($year % 400 == 0) || ( ($year % 4 == 0) && ($year % 100 !== 0) ) ) {   //判断是否是闰年 
    12.     $text = '29';        //闰年2
    13. } else { 
    14. $text = '28';          //平年2
    15. } else { 
    16. $text = '30';             //月小
    17. }
    18. return $text;

    21.}


    /**

    1.  * 判断某年的某月有多少天
    2.  * @return [type] [description]
    3.  */ 
    4. function daysInmonth1($year='',$month=''){
    5.      if(empty($year)) $year = date('Y'); 
    6.     if(empty($month)) $month = date('m');
    7.      $day = '01';
    8.     
    9.      //检测日期是否合法
    10. if(!checkdate($month,$day,$year)) return '输入的时间有误';
    11. //获取当年当月第一天的时间戳(,,,,,)
    12. $timestamp = mktime(0,0,0,$month,$day,$year);
    13. $result = date('t',$timestamp);
    14. return $result;

    16.}

  • 相关阅读:
    2017校赛 问题 F: 懒人得多动脑
    2017校赛 C: 不爱学习的小W【模拟】
    方程解的个数【数论】
    小兔蹦蹦跳【脑洞】
    例2-2显示文字
    例2-6 数值转换列表
    例2-3 转换数值
    例2-1 输出文字
    例1-1 求n!
    #文件1向文件中输出字符数据——fgetc
  • 原文地址:https://www.cnblogs.com/930115586qq/p/9488899.html
Copyright © 2011-2022 走看看