欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php calender(日歷)二個版本代碼示例(解決2038問題)

 更新時間:2013年12月24日 09:46:29   作者:  
一個簡單的php Calender(日歷),解決了2038問題,這樣在32位機和64位機上都可以用了,代碼很簡單,方便修改



注意32位機有2038問題,所以32位服務器的年限范圍1970年~2038年

我們還可以使用DateTime來規(guī)避這個問題(這樣與32位64位無關了)

復制代碼 代碼如下:

<?php
/**
 *
 * 我的日歷
 * date_default_timezone_set date mktime
 * @param int $year
 * @param int $month
 * @param string $timezone
 * @author fc_lamp
 * @blog: fc-lamp.blog.163.com
 */
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 < 1970 or $year >= 2038)
  {
   $year = date ( 'Y' );
  }
 } else
 {
  if ($year <= 0)
  {
   $year = date ( 'Y' );
  }

 }

 if ($month <= 0 or $month > 12)
 {
  $month = date ( 'm' );
 }

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

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

 //日歷頭
 $html = <<<HTML
<table width="500" border="1">
  <tr align="center">
    <td><a href="?y=$pretYear">上一年</a></td>
    <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td>
     <td><a href="?">回到今天</a></td>
    <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td>
 <td><a href="?y=$nextYear">下一年</a></td>
  </tr>
  <tr align="center">
    <td colspan="5">{$year}年{$month}月</td>
  </tr>
  <tr>
   <td colspan="5">
  <table width="100%" border="1">
   <tr align="center">
    <td style="background-color:#DAF0DD;">星期一</td>
    <td style="background-color:#DAF0DD;">星期二</td>
    <td style="background-color:#DAF0DD;">星期三</td>
    <td style="background-color:#DAF0DD;">星期四</td>
    <td style="background-color:#DAF0DD;">星期五</td>
    <td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td>
    <td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td>
   </tr>
HTML;

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

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

 //循環(huán)輸出天數(shù)
 $day = 1;
 $line = '';
 while ( $day <= $lastday )
 {
  $cday = $year . '-' . $month . '-' . $day;

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

  if ($day == 1)
  {
   $line = '<tr align="center">';
   $line .= str_repeat ( '<td>&nbsp;</td>', $nowWeek - 1 );
  }

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

  $line .= "<td $style>$day</td>";

  //一周結束
  if ($nowWeek == 7)
  {
   $line .= '</tr>';
   $html .= $line;
   $line = '<tr align="center">';
  }

  //全月結束
  if ($day == $lastday)
  {
   if ($nowWeek != 7)
   {
    $line .= str_repeat ( '<td>&nbsp;</td>', 7 - $nowWeek );
   }
   $line .= '</tr>';
   $html .= $line;

   break;
  }

  $day ++;
 }

 $html .= <<<HTML
  </table> 
 </td>
  </tr>
</table>
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;
}

使用DateTime 類解決2038問題,這樣不分32位與64位,代碼如下:

復制代碼 代碼如下:

<?php
/**
 *
 * 我的日歷(DateTime版本)
 * date_default_timezone_set date mktime
 * @param int $year
 * @param int $month
 * @param string $timezone
 * @author fc_lamp
 * @blog: fc-lamp.blog.163.com
 */
function myCalender($year = '', $month = '', $timezone = 'Asia/Shanghai')
{

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

 $nowDate = new DateTime();

 if ($year <= 0)
 {
  $year = $nowDate->format( 'Y' );
 }

 if ($month <= 0 or $month > 12)
 {
  $month = $nowDate->format('m' );
 }

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

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

 //日歷頭
 $html = <<<HTML
<table width="500" border="1">
  <tr align="center">
    <td><a href="?y=$pretYear">上一年</a></td>
    <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td>
     <td><a href="?">回到今天</a></td>
    <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td>
 <td><a href="?y=$nextYear">下一年</a></td>
  </tr>
  <tr align="center">
    <td colspan="5">{$year}年{$month}月</td>
  </tr>
  <tr>
   <td colspan="5">
  <table width="100%" border="1">
   <tr align="center">
    <td style="background-color:#DAF0DD;">星期一</td>
    <td style="background-color:#DAF0DD;">星期二</td>
    <td style="background-color:#DAF0DD;">星期三</td>
    <td style="background-color:#DAF0DD;">星期四</td>
    <td style="background-color:#DAF0DD;">星期五</td>
    <td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td>
    <td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td>
   </tr>
HTML;

 $currentDay = $nowDate->format('Y-m-j' );

 //當月最后一天
 $creatDate = new DateTime("$year-$nextMonth-0");
 $lastday = $creatDate->format('j');
 $creatDate = NULL;

 //循環(huán)輸出天數(shù)
 $day = 1;
 $line = '';
 while ( $day <= $lastday )
 {
  $cday = $year . '-' . $month . '-' . $day;

  //當前星期幾
  $creatDate = new DateTime("$year-$month-$day");
  $nowWeek = $creatDate->format('N');
  $creatDate = NULL;

  if ($day == 1)
  {
   $line = '<tr align="center">';
   $line .= str_repeat ( '<td>&nbsp;</td>', $nowWeek - 1 );
  }

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

  $line .= "<td $style>$day</td>";

  //一周結束
  if ($nowWeek == 7)
  {
   $line .= '</tr>';
   $html .= $line;
   $line = '<tr align="center">';
  }

  //全月結束
  if ($day == $lastday)
  {
   if ($nowWeek != 7)
   {
    $line .= str_repeat ( '<td>&nbsp;</td>', 7 - $nowWeek );
   }
   $line .= '</tr>';
   $html .= $line;

   break;
  }

  $day ++;
 }

 $html .= <<<HTML
  </table> 
 </td>
  </tr>
</table>
HTML;
 return $html;
}

相關文章

  • laravel實現(xiàn)查詢最后執(zhí)行的一條sql語句的方法

    laravel實現(xiàn)查詢最后執(zhí)行的一條sql語句的方法

    今天小編就為大家分享一篇laravel實現(xiàn)查詢最后執(zhí)行的一條sql語句的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-10-10
  • PHP集成百度Ueditor 1.4.3

    PHP集成百度Ueditor 1.4.3

    我們在做項目的時候經(jīng)常要遇到編輯器問題,就目前來看百度編輯器還是首選,今天我們就來看下如何在php中集成百度Ueditor,有相同需要的小伙伴參考下吧
    2014-11-11
  • Laravel 驗證碼認證學習記錄小結

    Laravel 驗證碼認證學習記錄小結

    這篇文章主要介紹了Laravel 驗證碼認證學習記錄小結,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-12-12
  • PHP+jQuery 注冊模塊的改進(三):更新到Smarty3.1

    PHP+jQuery 注冊模塊的改進(三):更新到Smarty3.1

    本文是PHP+jQuery 注冊模塊的改進的第三篇,主要記錄了講Smarty更新到最新的3.1版本,是篇非常使用的文章,有需要的朋友可以參考下
    2014-10-10
  • Laravel框架實現(xiàn)定時Task Scheduling例子

    Laravel框架實現(xiàn)定時Task Scheduling例子

    今天小編就為大家分享一篇Laravel框架實現(xiàn)定時Task Scheduling例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-10-10
  • PHP計算一年多少個星期和每周的開始和結束日期

    PHP計算一年多少個星期和每周的開始和結束日期

    這篇文章主要介紹了PHP計算每周的開始和結束日期,php實現(xiàn)計算一年多少周,同時計算出每一周的開始日期和結束日期,需要的朋友可以參考下
    2014-07-07
  • thinkPHP框架中執(zhí)行事務的方法示例

    thinkPHP框架中執(zhí)行事務的方法示例

    這篇文章主要介紹了thinkPHP框架中執(zhí)行事務的方法,結合實例形式分析了thinkPHP框架中使用模型中封裝的startTran()、Commit()及Rollback()方法執(zhí)行事務與回滾操作相關實現(xiàn)技巧,需要的朋友可以參考下
    2018-05-05
  • Centos PHP 擴展Xchche的安裝教程

    Centos PHP 擴展Xchche的安裝教程

    這篇文章主要介紹了Centos PHP 擴展Xchche的安裝教程的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-07-07
  • Yii框架的redis命令使用方法簡單示例

    Yii框架的redis命令使用方法簡單示例

    這篇文章主要介紹了Yii框架的redis命令使用方法,結合簡單實例形式分析了Yii框架redis命令相關的過期時間設置、數(shù)據(jù)存儲、添加、刪除、輸出等操作技巧,需要的朋友可以參考下
    2019-10-10
  • PHP-FPM 的管理和配置詳解

    PHP-FPM 的管理和配置詳解

    這篇文章主要介紹了PHP-FPM 的管理和配置詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-02-02

最新評論