zoukankan      html  css  js  c++  java
  • php 日历源码

    <?php
    date_default_timezone_set("Asia/shanghai");
    class CalendarForm {
     
            private $year;
            
            private $month;

            private $day;
           
            private $weekend;

            private $currentdate;
          
            private $dayofmonth;
           
            private $day_count;

            private $num;

            private $week = array();

            private $retunrhtml="";

            function __construct($year, $month) {
                    $this->makeWeeks($year, $month);
            }

            public function setYearMonth($year, $month) {
                    $this->year = $year;
                    $this->month = $month;
            }

            private function resetDayCount() {
                    $this->day_count = 1;
            }

            private function setFirstWeek() {
                    $this->num = 0;
            }

            public function getDayOfMonth($year, $month) {
                    $this->resetDayCount();
                    return date('t', mktime(0, 0, 0, $month, $this->day_count, $year ));
            }

            private function setDayOfMonth($year, $month) {
                    $this->dayofmonth = $this->getDayOfMonth($year, $month);
            }

           
            private function getDayOfWeek() {
                    return date('w', mktime(0, 0, 0, $this->month, $this->day_count, $this->year ));
            }


           public function getNextMonth() {
                    return date('m', mktime(0, 0, 0, $this->month, 28, $this->year )+432000);
            }

            public function getNextYear() {
                    return date('Y', mktime(0, 0, 0, $this->month, 28, $this->year )+432000);
            }

            public function getPrevMonth() {
                    return date('m', mktime(0, 0, 0, $this->month, 1, $this->year )-432000);
            }

            public function getPrevYear() {
                    return date('Y', mktime(0, 0, 0, $this->month, 1, $this->year )-432000);
            }

            private function makeWeeks($year, $month) {

                    $this->setYearMonth($year, $month);
                    $this->setDayOfMonth($this->year, $this->month);
                    $this->setFirstWeek();

                    $this->num = 0;
                    for($i = 0; $i < 7; $i++) {
                          
                            $dayofweek = $this->getDayOfWeek();
                            $dayofweek = $dayofweek - 1;
                            if($dayofweek == -1) $dayofweek = 6;
                            if($dayofweek == $i) {
                                    $this->week[$this->num][$i] = $this->day_count;
                                    $this->day_count++;
                            } else {
                                    $this->week[$this->num][$i] = "";
                            }
                    }
                   while(true) {
                            $this->num++;
                            for($i = 0; $i < 7; $i++) {
                                    $this->week[$this->num][$i] = $this->day_count;
                                    $this->day_count++;
                                    if($this->day_count > $this->dayofmonth) break;
                            }
                            if($this->day_count > $this->dayofmonth) break;
                    }

            }

            public function getCalendarHeader() {
                    $this->retunrhtml =
                                                    "<table cellpadding=2 cellspacing=0 border=1 style=\"margin-left: auto; margin-right: 0px;\">".
                                                    "<tbody>".
                                                    "<tr><th colspan=\"7\">".$this->month."/".$this->year."</th></tr>".
                                                    "<tr>".
                                                    "<th style=\"text-align: center;\">周一</th>".
                                                    "<th style=\"text-align: center;\">周二</th>".
                                                    "<th style=\"text-align: center;\">周三</th>".
                                                    "<th style=\"text-align: center;\">周四</th>".
                                                    "<th style=\"text-align: center;\">周五</th>".
                                                    "<th style=\"text-align: center;\"><span style=\"color: #ff0000;\">周六</span></th>".
                                                    "<th style=\"text-align: center;\"><span style=\"color: #ff0000;\">周日</span></th>".
                                                    "</tr>";
            }

            public function getCalendarFooter() {
                    $this->retunrhtml.="</tbody></table>";
            }

            public function getBeginTR() {
                    $this->retunrhtml.="<tr>";
            }

            public function getEndTR() {
                    $this->retunrhtml.="</tr>";
            }

            protected function getDay() {
                    return $this->day;
            }

            protected function getMonth() {
                    return $this->month;
            }

            protected function getYear() {
                    return $this->year;
            }

            protected function isWeekend() {
                    return $this->weekend;
            }

            protected function isCurrent() {
                    return $this->currentdate;
            }
            
            public function getTDHref() {
                    return $this->getDay();
            }

            public function getTD() {
                    $td="td"; if ($this->isCurrent()) $td="th";
                    $this->retunrhtml.="<$td style=\"text-align: right;\">".$this->getTDHref()."</$td>";
            }
            
            public function getTDWeekend() {
                    $td="td"; if ($this->isCurrent()) $td="th";
                    $this->retunrhtml.="<$td style=\"text-align: right;\"><font color=red>".$this->getTDHref()."</font></$td>";
            }

            protected function makeCodeMonth($year, $month) {
                    $this->makeWeeks($year, $month);
                    $this->getCalendarHeader();
                    for($i = 0; $i < count($this->week); $i++) {
                            $this->getBeginTR();
                            for($j = 0; $j < 7; $j++) {

                                    if(!empty($this->week[$i][$j])) {
                                            $this->day = $this->week[$i][$j];
                                            $this->currentdate = 0;
                                            if ( $this->year==date('Y') && $this->month==date('m') && $this->day==date('j')) $this->currentdate = 1;
                                            if($j == 5 || $j == 6) {
                                                    $this->weekend = 1;
                                                    $this->getTDWeekend();
                                            } else {
                                                    $this->weekend = 0;
                                                    $this->getTD();
                                            }

                                    } else $this->retunrhtml.="<td>&nbsp;</td>";

                            }
                            $this->getEndTR();
                    }
                    $this->getCalendarFooter();
            }

            public function getCodeMonth() {
                    $this->makeCodeMonth($this->year, $this->month);
                    return $this->retunrhtml;
            }

            public function showCodeMonth() {
                    echo $this->getCodeMonth();
            }

    }

    class TechCalendarForm extends CalendarForm {
            public function getTDHref() {
                    if ($this->isWeekend()) $font = "<font color=\"#FF3F4F\">"; else $font = "<font color=\"#4A5B6C\">";
                    return "<a href=\"".$_SERVER["PHP_SELF"]."?action=showdate&date=".parent::getYear()."-".parent::getMonth()."-".parent::getDay()."\">".$font.parent::getDay()."</font></a>";
            }
    }


    ?>
    <html>
    <head>
     <style type="text/css">  
     .align-center{  
         margin:0 auto;      /* 居中 这个是必须的,,其它的属性非必须 */  
         789px;        /* 给个宽度 顶到浏览器的两边就看不出居中效果了 */  
        // background:red;     /* 背景色 */  
         text-align:center;  /* 文字等内容居中 */  
     }  
     </style>
    </head>
    <body>
    <div class="align-center">
    <?php
        //$cal= new TechCalendarForm(2009,10);
        $cal= new CalendarForm(2009,10);
        $cal->showCodeMonth();
    ?>
    </div>
    </body>
    </html>

  • 相关阅读:
    我开发中的用到的几个框架
    关于ASP.NETCore的分享之学习路线
    首个.NET5+Vue.js业务模块化快速开发框架【NetModular】发布
    [C#] (原创)一步一步教你自定义控件 —— 系列文章
    EFS加密
    博客园样式美化:给博客添加一个音乐播放器
    XSS语义分析
    TCP回放攻击 & DDoS脉冲攻击Hit and Run IoT僵尸网络 在DDoS攻击黑产领域最活跃
    小样本学习,阿里做得比较早,但是效果未知——小样本有3类解决方法(算法维度):迁移学习、元学习(模型基础上学习模型)、度量学习(相似度衡量,也就是搜索思路),数据维度还有GAN
    真实世界中的开集识别问题(Open-Set Recognition Problem)——Walter J. Scheirer研究是最深的,安全里已经有研究了,但是感觉只是触及了皮毛而已
  • 原文地址:https://www.cnblogs.com/likwo/p/1691832.html
Copyright © 2011-2022 走看看