<tfoot id='C5TSy'></tfoot>
  • <legend id='C5TSy'><style id='C5TSy'><dir id='C5TSy'><q id='C5TSy'></q></dir></style></legend>

    <small id='C5TSy'></small><noframes id='C5TSy'>

      1. <i id='C5TSy'><tr id='C5TSy'><dt id='C5TSy'><q id='C5TSy'><span id='C5TSy'><b id='C5TSy'><form id='C5TSy'><ins id='C5TSy'></ins><ul id='C5TSy'></ul><sub id='C5TSy'></sub></form><legend id='C5TSy'></legend><bdo id='C5TSy'><pre id='C5TSy'><center id='C5TSy'></center></pre></bdo></b><th id='C5TSy'></th></span></q></dt></tr></i><div id='C5TSy'><tfoot id='C5TSy'></tfoot><dl id='C5TSy'><fieldset id='C5TSy'></fieldset></dl></div>

          <bdo id='C5TSy'></bdo><ul id='C5TSy'></ul>

        在php中创建每周日历

        时间:2023-12-01

        <tfoot id='a8DXW'></tfoot>
            <legend id='a8DXW'><style id='a8DXW'><dir id='a8DXW'><q id='a8DXW'></q></dir></style></legend>
            <i id='a8DXW'><tr id='a8DXW'><dt id='a8DXW'><q id='a8DXW'><span id='a8DXW'><b id='a8DXW'><form id='a8DXW'><ins id='a8DXW'></ins><ul id='a8DXW'></ul><sub id='a8DXW'></sub></form><legend id='a8DXW'></legend><bdo id='a8DXW'><pre id='a8DXW'><center id='a8DXW'></center></pre></bdo></b><th id='a8DXW'></th></span></q></dt></tr></i><div id='a8DXW'><tfoot id='a8DXW'></tfoot><dl id='a8DXW'><fieldset id='a8DXW'></fieldset></dl></div>
            • <bdo id='a8DXW'></bdo><ul id='a8DXW'></ul>

              <small id='a8DXW'></small><noframes id='a8DXW'>

                  <tbody id='a8DXW'></tbody>
                • 本文介绍了在php中创建每周日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我创建了一个 php 日历,一次显示一周.这是我创建的代码

                  I have created a php calender which will show one week at a time.Here is the code i have created

                   <?php
                     $week = date("W");
                     $year = (isset($_GET['year']))?$_GET['year']:date("Y");
                     $week = (isset($_GET['week']))?$_GET['week']:Date('W');
                     if($week>53){
                       $year+= 1;
                       $week=1;
                     }
                   ?>
                  
                   <a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week+1).'&year='.$year; ?>">Next  Week</a> <!--Next week-->
                  
                   <a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week-1).'&year='.$year; ?>">Pre Week</a> <!--Previous week-->
                  
                   <table border="1px">
                   <tr>
                   <td>Employee</td>
                   <?php
                   for($day=1; $day<=7; $day++)
                   {
                      $d = strtotime($year."W".$week.$day);                           
                      echo "<td>".date('l',$d )."<br>";
                      echo date('d M',$d)."</td>";
                   }
                   ?>
                   </tr>
                  

                  当我试图去下周时,它工作正常.但是当年份变化时,它不适用于明年.

                  when i am trying to go to the next week it is working correctly. But when the year is changing it is not working for the next year.

                  推荐答案

                  将周计算留给 DateTime::setIsoDate() 方法.

                  Leave the week calculation to the DateTime::setIsoDate() method.

                  这是解决您问题的最简单和最佳的解决方案:

                  Here is the simplest and best solution for your problem :

                  <?php
                  $dt = new DateTime;
                  if (isset($_GET['year']) && isset($_GET['week'])) {
                      $dt->setISODate($_GET['year'], $_GET['week']);
                  } else {
                      $dt->setISODate($dt->format('o'), $dt->format('W'));
                  }
                  $year = $dt->format('o');
                  $week = $dt->format('W');
                  ?>
                  
                  <a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week-1).'&year='.$year; ?>">Pre Week</a> <!--Previous week-->
                  <a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week+1).'&year='.$year; ?>">Next Week</a> <!--Next week-->
                  
                  <table>
                      <tr>
                          <td>Employee</td>
                  <?php
                  do {
                      echo "<td>" . $dt->format('l') . "<br>" . $dt->format('d M Y') . "</td>
                  ";
                      $dt->modify('+1 day');
                  } while ($week == $dt->format('W'));
                  ?>
                      </tr>
                  </table>
                  

                  这篇关于在php中创建每周日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:iCalendar .ics 在 iOS 上接受/拒绝 下一篇:调度与夏令时

                  相关文章

                    • <bdo id='hCWoZ'></bdo><ul id='hCWoZ'></ul>

                    1. <small id='hCWoZ'></small><noframes id='hCWoZ'>

                      <tfoot id='hCWoZ'></tfoot>

                    2. <i id='hCWoZ'><tr id='hCWoZ'><dt id='hCWoZ'><q id='hCWoZ'><span id='hCWoZ'><b id='hCWoZ'><form id='hCWoZ'><ins id='hCWoZ'></ins><ul id='hCWoZ'></ul><sub id='hCWoZ'></sub></form><legend id='hCWoZ'></legend><bdo id='hCWoZ'><pre id='hCWoZ'><center id='hCWoZ'></center></pre></bdo></b><th id='hCWoZ'></th></span></q></dt></tr></i><div id='hCWoZ'><tfoot id='hCWoZ'></tfoot><dl id='hCWoZ'><fieldset id='hCWoZ'></fieldset></dl></div>
                      <legend id='hCWoZ'><style id='hCWoZ'><dir id='hCWoZ'><q id='hCWoZ'></q></dir></style></legend>