月球-I型,月份日历生成器----基于PHP7.3
- 生成月份周日的类
<?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的更多相关文章
- 关于windows下基于php7.0.2下编写的第一个扩展
网上的教程是比较多的,但是基于php7+windows的教程非常之少,通过几天的摸索及参考很多资料,终于发现如下可以运行. php7要求使用vc2015,同时安装sdk,我使用的是8.1的window ...
- JAVA 打印指定月份日历
package learnExercise; import java.util.Scanner; public class PrintCalender { /** * @param args */ p ...
- 对象创建型模式------Builder(生成器或建造者模式)(2)
链接转自:http://blog.csdn.net/wuzhekai1985/article/details/6667467 主要思想是:首先有个指挥家思想者将大体的设计思路设计出来,然后寻找一部分工 ...
- 对象创建型模式------Builder(生成器)
本文系转载,转载地址http://blog.sina.com.cn/s/blog_59b6af690100zj3l.html,只供自己学习使用. 假设现在有三种产品,是玩具,都是由三部分组成,头,身体 ...
- 基于LAMP php7.1搭建owncloud云盘与ceph对象存储S3借口整合案例
ownCloud简介 是一个来自 KDE 社区开发的免费软件,提供私人的 Web 服务.当前主要功能包括文件管理(内建文件分享).音乐.日历.联系人等等,可在PC和服务器上运行. 简单来说就是一个基于 ...
- 基于jQuery 常用WEB控件收集
Horizontal accordion: jQuery 基于jQuery开发,非常简单的水平方向折叠控件. Horizontal accordion: jQuery jQuery-Horizonta ...
- PHP7革新与性能优化
有幸参与2015年的PHP技术峰会(PHPCON),听了鸟哥(惠新宸)的关于PHP7的新特性和性能优化的分享,一切都令人感到激动.鸟哥是国内最权威的PHP专家,他的分享有很多非常有价值的东西,我通过整 ...
- python 12 生成器
目录 1. 生成器 yeild 2. 推导式 2.1 列表推导式: 2.2 生成器推导式: 2.3 字典推导式: 2.4 集合推导式: 3. 内置函数(一) 1. 生成器 yeild 生成器的本质就是 ...
- R型思维模式对软件开发的影响(草稿)
The pragmatic programmers 一直在工作之余读些书,之前主要是纯英文版的计算机相关的算法,编译器,数学等,想通过读这些书来提高自己每日工作效能,结果收效甚微.一是,因为纯英文的书 ...
随机推荐
- MySQL(六) 索引
索引与优化 1.选择索引的数据类型 MySQL支持很多数据类型,选择合适的数据类型存储数据对性能有很大的影响.通常来说,可以遵循以下一些指导原则: (1)越小的数据类型通常更好:越小的数据类型通常在磁 ...
- navicat-use
https://blog.csdn.net/weixin_44496987/article/details/87186071
- diy操作系统 附录:gcc栈帧开启与关闭
在gcc命令行参数中可以使用-fno-omit-frame-pointer来开启栈帧的使用,或者使用-fomit-frame-pointer选项来关闭. 然而,也可以针对某一个函数进行配置方法如下,这 ...
- spring cloud微服务实践七
在spring cloud 2.x以后,由于zuul一直停滞在1.x版本,所以spring官方就自己开发了一个项目 Spring Cloud Gateway.作为spring cloud微服务的网关组 ...
- gmpy安装使用方法
gmpy是一种C编码的Python扩展模块,提供对GMP(或MPIR)多精度算术库的访问.gmpy 1.17是1.x系列的最终版本,没有进一步的更新计划.所有进一步的开发都在2.x系列(也称为gmpy ...
- archive_lag_target参数
需求,由于一套生产环境归档日志切换频率过低,建议修改参数,使其间隔一定时间周期自动切换生成归档日志; SQL>; THREAD# SEQUENCE# TO_CHAR(COMPLETION_TIM ...
- 01背包变种 第k解问题 hdu 2639
先说说普通01包的状态问题吧 普通的01背包,在状态转移的过程中为了求出最优解,一定是遍历了所有的情况 然后再求的最优解.那么对于第k最优解问题,我们只需要再加一个维度,用来记录每一个状态k优解的状态 ...
- [Vue]vue-router嵌套路由(子路由)
总共添加两个子路由,分别命名Collection.vue(我的收藏)和Trace.vue(我的足迹) 1.重构router/index.js的路由配置,需要使用children数组来定义子路由,具体如 ...
- [APB VNext 笔记] UI
一直想给我做的服务写UI.但苦于现在ABPVNext框架对SPA支持不好.只好先放弃VUE.先弄个UI在说.ABPVNext中的框架都是用Helper封装好的Label.不知道怎么使用,于是翻源代码. ...
- wstngfw中配置snort
wstngfw中配置snort 概述 Snort是入侵检测和预防系统.它可以将检测到的网络事件记录到日志并阻止它们.Snort使用称为规则的检测签名进行操作. Snort规则可以由用户自定义创建,或者 ...