search
Homephp教程php手册php Calender(日历)代码分享

php Calender(日历)代码分享

Jun 13, 2016 am 09:46 AM
datedefaultphpcodesharecopycalendar

代码如下:

复制代码 代码如下:


/**
 *
 * 我的日历
 * date_default_timezone_set date mktime
 * @param int $year
 * @param int $month
 * @param string $timezone
 * @author fc_lamp
 */
function myCalender($year = '', $month = '', $timezone = 'Asia/Shanghai')
{

    date_default_timezone_set ( $timezone );
    $year = abs ( intval ( $year ) );
    $month = abs ( intval ( $month ) );

    //是否是32位机
    if (is32())
    {
        if ($year = 2038)
        {
            $year = date ( 'Y' );
        }
    } else
    {
        if ($year         {
            $year = date ( 'Y' );
        }

    }

    if ($month 12)
    {
        $month = date ( 'm' );
    }

    //上一年
    $pretYear = $year - 1;
    //上一月
    $mpYear = $year;
    $preMonth = $month - 1;
    if ($preMonth     {
        $preMonth = 1;
        $mpYear = $pretYear;
    }

    //下一年
    $nextYear = $year + 1;
    //下一月
    $mnYear = $year;
    $nextMonth = $month + 1;
    if ($nextMonth > 12)
    {
        $nextMonth = 1;
        $mnYear = $nextYear;
    }

    //日历头
    $html =


 
   
   
    
   
   
 
 
   
 
 
     
 
上一年 上一月 回到今天 下一月 下一年
{$year}年{$month}月

       
           
               
               
               
               
               
               
               
           
HTML;

    $currentDay = date ( 'Y-m-j' );

    //当月最后一天
    $lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );

    //循环输出天数
    $day = 1;
    $line = '';
    while ( $day     {
        $cday = $year . '-' . $month . '-' . $day;

        //当前星期几
        $nowWeek = date ( 'N', mktime ( 0, 0, 0, $month, $day, $year ) );

        if ($day == 1)
        {
            $line = '';
            $line .= str_repeat ( '', $nowWeek - 1 );
        }

        if ($cday == $currentDay)
        {
            $style = 'style="color:red;"';
        } else
        {
            $style = '';
        }

        $line .= "";

        //一周结束
        if ($nowWeek == 7)
        {
            $line .= '';
            $html .= $line;
            $line = '';
        }

        //全月结束
        if ($day == $lastday)
        {
            if ($nowWeek != 7)
            {
                $line .= str_repeat ( '', 7 - $nowWeek );
            }
            $line .= '';
            $html .= $line;

            break;
        }

        $day ++;
    }

    $html .=        
星期一 星期二 星期三 星期四 星期五 星期六 星期天
 $day
 
   
   

HTML;
    return $html;
}

/**
 *
 * 检测是否是32位机
 * @author fc_lamp
 * @blog: fc-lamp.blog.163.com
 */
function is32()
{
    $is32 = False;
    if (strtotime ( '2039-10-10' ) === False)
    {
        $is32 = True;
    }
    return $is32;
}

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.