亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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



注意32位機(jī)有2038問題,所以32位服務(wù)器的年限范圍1970年~2038年

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

復(fù)制代碼 代碼如下:

<?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位機(jī)
 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' );

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

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

  //當(dāng)前星期幾
  $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>";

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

  //全月結(jié)束
  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;
}

/**
 *
 * 檢測(cè)是否是32位機(jī)
 * @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位,代碼如下:

復(fù)制代碼 代碼如下:

<?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' );

 //當(dāng)月最后一天
 $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;

  //當(dāng)前星期幾
  $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>";

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

  //全月結(jié)束
  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;
}

相關(guān)文章

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

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

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

    PHP集成百度Ueditor 1.4.3

    我們?cè)谧鲰?xiàng)目的時(shí)候經(jīng)常要遇到編輯器問題,就目前來看百度編輯器還是首選,今天我們就來看下如何在php中集成百度Ueditor,有相同需要的小伙伴參考下吧
    2014-11-11
  • Laravel 驗(yàn)證碼認(rèn)證學(xué)習(xí)記錄小結(jié)

    Laravel 驗(yàn)證碼認(rèn)證學(xué)習(xí)記錄小結(jié)

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

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

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

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

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

    PHP計(jì)算一年多少個(gè)星期和每周的開始和結(jié)束日期

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

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

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

    Centos PHP 擴(kuò)展Xchche的安裝教程

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

    Yii框架的redis命令使用方法簡(jiǎn)單示例

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

    PHP-FPM 的管理和配置詳解

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

最新評(píng)論