• 生成月份周日的类
<?php
class mycalendar
{
function __construct($year,$mon)
{
$this->nianyue=$year.'-'.$mon.'-'.'';
$this->firstday=strtotime(date($this->nianyue));
$this->m = intval(date('m',$this->firstday));
$this->wdaylist=array();
$this->lday = strtotime(date($this->nianyue).'+1 month -1 day');
//echo "时间戳:".date('Y-m-d',$this->lday)."\n";
}
function startday()
{
$w = date('w',$this->firstday);
$diffdays=;
if ($w!=)
{
$diffdays= -$w;
}
$this->firstday = strtotime(date('Y-m-d',strtotime($this->nianyue))."+".$diffdays." day");
//array_push($this->wdaylist,$w);
//echo "\n".date('Y-m-d',$this->firstday);
//echo "\n".$this->firstday;
return $this->firstday;
}
function addwday()
{
$curday = $this->startday();
while (true){
if(intval(date('m',$curday)!=$this->m))
{
break;
}
//echo date('Y-m-d',$curday)."\n";
array_push($this->wdaylist,date('Y-m-d',$curday));
$curday=strtotime(date('Y-m-d',$curday)."+7 day");
}
return $this->wdaylist;
}
}
  • 根据每个周日推算每个周的日期
<?php
require('mycal.php');
class gencal
{
function __construct(array $wkday)
{
$this->time = strtotime($wkday[count($wkday)-]);
$this->wdaylist=$wkday;
$this->ldday= date('m',$this->time);
$this->ttday= date('t',$this->time);
$this->firstday=strtotime($wkday[]);
}
function diffdays()
{
$lastday = ;
if($this->ldday<$this->ttday)
{
$lastday = strtotime(date('Y-m-d',$this->time)."+1 day");
}
//echo "this day:".date('Y-m-d',$lastday);
return $lastday;
}
function adddays()
{
//生成日期辗转相加
$genarray = array();
$startday = $this->diffdays();
//echo $startday."\n";
$newday = date('Y-m-d',strtotime(date('Y-m-d',strtotime($this->wdaylist[count($this->wdaylist)-]))."+1 day"));
//echo 'newday:'. $newday;
$genarray[] = $newday;
for ($i=;$i<;$i++)
{
$startday=strtotime(date('Y-m-d',$startday)."+1 day");
$genarray[] = date('Y-m-d',$startday);
/*array_push($genarray,strtotime(date('Y-m-d',$startday).'+1 day'));*/
}
return $genarray;
}
function minus($startday){
//辗转相减法
$thisweek=array();
$startday = strtotime($startday);
$thisweek[]=date('Y-m-d',$startday);
//echo $startday;
for($i=;$i>;$i--)
{
$startday=strtotime(date('Y-m-d',$startday)."-1 day");
$thisweek[$i]=date('Y-m-d',$startday);
//echo date('Y-m-d',$startday)."---"."\n";
}
return $thisweek;
}
function gendaylist()
{
$finallist=array();
for ($i=;$i<count($this->wdaylist);$i++)
{
array_push($finallist,$this->minus($this->wdaylist[$i]));
}
array_push($finallist,$this->adddays());
return $finallist;
}
}
  • 测试
$cal = new mycalendar(,);
$wuwa= new gencal($cal->addwday());
//$wuwa->adddays();
print_r($wuwa->gendaylist());
  • 输出结果
Array
(
[] => Array
(
[] => --
[] => --
[] => --
[] => --
[] => --
[] => --
[] => --
) [] => Array
(
[] => --
[] => --
[] => --
[] => --
[] => --
[] => --
[] => --
) [] => Array
(
[] => --
[] => --
[] => --
[] => --
[] => --
[] => --
[] => --
) [] => Array
(
[] => --
[] => --
[] => --
[] => --
[] => --
[] => --
[] => --
) [] => Array
(
[] => --
[] => --
[] => --
[] => --
[] => --
[] => --
[] => --
) [] => Array
(
[] => --
[] => --
[] => --
[] => --
[] => --
[] => --
[] => --
) )

最新文章

  1. C# 读取XML注释
  2. Android欢迎界面
  3. Log4J详解
  4. IllegalStateException : Web app root system property already set to different value问题详解
  5. iOS 利用constraint实现2个控件上下的空白是相等的
  6. linux mysql服务器迁移
  7. codereview
  8. Dev gridview新增一行自动获得焦点并打开编辑模式
  9. 错误提示:类型“GridView”的控件“GridView1”必须放在具有 runat=server 的窗体标记内 .
  10. USACO3.31Riding the Fences(输出欧拉路径)
  11. WebMagic开源垂直爬虫介绍
  12. Linux下修改字符集,转自
  13. [转]laravel 4之视图及Responses
  14. 【数据结构】算法 LinkList (Merge Two Sorted Lists)
  15. UML作业第三次:分析《书店图书销售管理系统》,绘制类图
  16. day02 运算符
  17. Druid数据库连接池
  18. BZOJ.2597.[WC2007]剪刀石头布(费用流zkw)
  19. CoordinatorLayout实现的效果(标题栏效果)
  20. Oracle插入(insert into)

热门文章

  1. 2、head 标签学习
  2. Linux由于物理节点故障导致的异常重启-Case1
  3. Linux &quot;yin&quot;才们的奇&quot;yin&quot;小技巧 --请用东北发音夸他们
  4. 只学python行吗
  5. 个人整理Python代码实例
  6. 十、LCD的framebuffer设备驱动
  7. SysTick 定时实验(非中断)
  8. Struts2简介、初步使用
  9. CentOS7 服务器连接超时自动断开问题解决
  10. Tokitsukaze and Strange Rectangle CodeForces - 1191F (树状数组,计数)