zoukankan      html  css  js  c++  java
  • php 循环日历

    $time = strtotime('2018-06');
    
    
        $b_month = date('m');  //本月
        $b_month_last_day = date('t', $time);  //本月最后一天
        $m_l_day = date('w', strtotime(date('Y-m', $time))); //本月第一天的星期
        $last_month = date('t', strtotime('-1 month', $time));  //上个月最后一天
    
        $last_month_day  = 0;
        //补齐本月第一天的星期
        if($m_l_day == 0) {
            //星期日  差6天
            $last_month_day = 6;
        }else {
            $last_month_day = $m_l_day-1;
        }
    
        $rili_array = $last_rili = $next_rili = array();
    
        for($i=1; $i<=$b_month_last_day; $i++) {
            if(date('Y-m', $time) == date('Y-m') && $i < date('d')) {
                $rili_array['thismonth-'.$i] = $i;
            }elseif(date('Y-m', $time) == date('Y-m') && $i == date('d')) {
                $rili_array["thismonth-".$i.'-today'] = $i;
            }else {
                $rili_array["thismonth-".$i.'-tomorrow'] = $i;
            }
        }
    
        if(!empty($last_month_day)) {
            for($j=1; $j<=$last_month_day; $j++) {
                $last_rili['no_thismonth_'.$j] = $last_month-$j+1;
            }
        }
    
        $rili_array = array_merge(array_reverse($last_rili), $rili_array);
    
        $count = count($rili_array);
        //共六个星期   补齐
        if($count/7 != 6) {
            for($i = 1; $i<= 42-$count; $i++) {
                $next_rili['no_thismonth-'.$i] = $i;
            }
        }
    
        $rili_array = array_merge($rili_array, $next_rili);
    

     数组的key是为了方便后期的处理,可以不用在意!

     这个日历是周一到周日, 如果是周日开始的话,$last_month_day = 5 就行!!!!!!!!!

  • 相关阅读:
    目录结构
    RabbitMQ 将监听的IP从localhost修改为指定IP
    概念
    RabbitMQ 基础概念
    修改shell提示符的显示格式
    VIM常用设置
    RabbitMQ 开启WEB管理
    用pecl/pear独立编译PHP扩展 vs. 把扩展编译到PHP内核中
    安装composer
    安装php-amqplib(RabbitMQ的phpAPI)
  • 原文地址:https://www.cnblogs.com/zheart/p/9233168.html
Copyright © 2011-2022 走看看