• 生成月份周日的类
<?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. K8S从入门到放弃系列-(10)kubernetes集群之kube-proxy部署

    摘要: kube-proxy的作用主要是负责service的实现,具体来说,就是实现了内部从pod到service和外部的从node port向service的访问 新版本目前 kube-proxy ...

  2. ubuntu18和windows10双系统时间不同步问题(Ubuntu)

    1.安装并校准时间 sudo apt install ntpdate sudo ntpdate time.windows.com 2.写入硬件配置 sudo hwclock --localtime - ...

  3. Python笔记001-Python入门

    第一章:Python入门 1.Python介绍 1.1 简介 Python是一种解释型,面向对象的语言.由吉多·范罗苏姆(Guido van Rossum)于1989年发明,1991年正式公布.官网: ...

  4. ubuntu svn 安装

    deepin@deepin:~$ sudo apt-get install rabbitvcs-rabbitvcs-cli rabbitvcs-core rabbitvcs-gedit rabbitv ...

  5. BZOJ3879 SvT(后缀树+虚树)

    对反串建SAM得到后缀树,两后缀的lcp就是其在后缀树上lca的len值,于是每次询问对后缀树建出虚树并统计答案即可. #include<iostream> #include<cst ...

  6. Task执行多次

    项目中,曾经出现过启动时数据库连接数瞬间增大,当时并没有注意该问题. 后期,由于Task任务多次执行,才着手查看这个问题,经排查,由于tomcat中webapp配置多次,导致webapp被扫描多次(配 ...

  7. .net Core CLR

    .net Core CLR是开源的.大部分文件是C++写成.这样他就可以编译后再不同的平台运行. https://github.com/dotnet/coreclr

  8. 【原创】大叔经验分享(84)spark sql中设置hive.exec.max.dynamic.partitions无效

    spark 2.4 spark sql中执行 set hive.exec.max.dynamic.partitions=10000; 后再执行sql依然会报错: org.apache.hadoop.h ...

  9. css3flex布局实现商品列表

    首先看图 手机商场经常会有商品列表功能,这样其实可以用flex布局实现 注意两个地方: 1.商品列表平衡间距(flex布局的换行加两端对齐) 2.中间文字行数不一样,会出现下方留下空白,如何解决(fl ...

  10. undefined reference to `udev_device_get_action'

    /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libusb-1.0.a(libusb_1_0_la-linux_udev.o): In ...