• 生成月份周日的类
<?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
(
[] => --
[] => --
[] => --
[] => --
[] => --
[] => --
[] => --
) )

月球-I型,月份日历生成器----基于PHP7.3的更多相关文章

  1. 关于windows下基于php7.0.2下编写的第一个扩展

    网上的教程是比较多的,但是基于php7+windows的教程非常之少,通过几天的摸索及参考很多资料,终于发现如下可以运行. php7要求使用vc2015,同时安装sdk,我使用的是8.1的window ...

  2. JAVA 打印指定月份日历

    package learnExercise; import java.util.Scanner; public class PrintCalender { /** * @param args */ p ...

  3. 对象创建型模式------Builder(生成器或建造者模式)(2)

    链接转自:http://blog.csdn.net/wuzhekai1985/article/details/6667467 主要思想是:首先有个指挥家思想者将大体的设计思路设计出来,然后寻找一部分工 ...

  4. 对象创建型模式------Builder(生成器)

    本文系转载,转载地址http://blog.sina.com.cn/s/blog_59b6af690100zj3l.html,只供自己学习使用. 假设现在有三种产品,是玩具,都是由三部分组成,头,身体 ...

  5. 基于LAMP php7.1搭建owncloud云盘与ceph对象存储S3借口整合案例

    ownCloud简介 是一个来自 KDE 社区开发的免费软件,提供私人的 Web 服务.当前主要功能包括文件管理(内建文件分享).音乐.日历.联系人等等,可在PC和服务器上运行. 简单来说就是一个基于 ...

  6. 基于jQuery 常用WEB控件收集

    Horizontal accordion: jQuery 基于jQuery开发,非常简单的水平方向折叠控件. Horizontal accordion: jQuery jQuery-Horizonta ...

  7. PHP7革新与性能优化

    有幸参与2015年的PHP技术峰会(PHPCON),听了鸟哥(惠新宸)的关于PHP7的新特性和性能优化的分享,一切都令人感到激动.鸟哥是国内最权威的PHP专家,他的分享有很多非常有价值的东西,我通过整 ...

  8. python 12 生成器

    目录 1. 生成器 yeild 2. 推导式 2.1 列表推导式: 2.2 生成器推导式: 2.3 字典推导式: 2.4 集合推导式: 3. 内置函数(一) 1. 生成器 yeild 生成器的本质就是 ...

  9. R型思维模式对软件开发的影响(草稿)

    The pragmatic programmers 一直在工作之余读些书,之前主要是纯英文版的计算机相关的算法,编译器,数学等,想通过读这些书来提高自己每日工作效能,结果收效甚微.一是,因为纯英文的书 ...

随机推荐

  1. javascript当中火狐的firebug如何单步调试程序?

    [学习笔记] 2)火狐的firebug如何单步调试程序 马克-to-win:火狐中:工具/web 开发者/调试器,开始时没有文件,在浏览器当中点刷新按钮,文件就加载进来了. 文章转载自原文:https ...

  2. 《Mysql - 索引(唯一索引和普通索引的选择)Change Buffer 》

    一:概述 - 如果业务代码已经保证了不会写入重复的身份证号. - 从性能的角度考虑,你会为这个身份证号,选择唯一索引还是普通索引呢?选择的依据是什么呢? - 这就要从他们的执行过程看起. 二:唯一索引 ...

  3. Html大段文本自适应换行显示-SSM

    只处理前端: <style> .ctl{ table-layout:fixed } .ctl td{ word-break:break-all } </style> <d ...

  4. msql 数据类型

    1.数据类型 #1. 数字: 整型:tinyinit int bigint 小数: float :在位数比较短的情况下不精准 double :在位数比较长的情况下不精准 0.0000012301231 ...

  5. WUSOJ 1293: Fibonacci数列(Java)

    题目:

  6. C#获取ip

    string name = Dns.GetHostName(); string ip = Dns.GetHostAddresses(name).First().ToString();

  7. Unity塔防游戏的创建

    看了下塔防游戏的教程,比我想像的还简单一些,有些收获: (1)敌人的移动路径,其时比较简单,用了N个Empty GameObject作为路径点,然后做一个总的Empty GameObject 作为父级 ...

  8. opencv-01--图像的遍历

    遍历图像的4种方式 一.at<typename>(i,j) Mat类提供了一个at的方法用于取得图像上的点,它是一个模板函数,可以取到任何类型的图像上的点.下面我们通过一个图像处理中的实际 ...

  9. Spring MVC通过拦截器处理sql注入、跨站XSS攻击风险

    sql注入就是通过url或者post提交数据时候,字符串类型的参数会被别人利用传入sql语句,最终破坏数据库或者达到一些见不得人的目的. 有时候因为业务需要url中会带一些参数,比如 ?type=xx ...

  10. dubbo常见异常及解决方式

    1.出现RpcException: Failed to invoke the method post in the service com.xxx.xxx.xxx异常怎么办?表示调用失败1.检查网络是 ...