strtotime---用于接收两个参数,第一个参数是格式化的日期数据如:date('Y-m-d'),第二个参数有如'+7 day'

  • 函数版
<?php
$firstsunday = strtotime(date('Y-m-01'));
$thisy = intval(date('m'));
$diffdays=;
$count = ;
if (date('w',strtotime(date('Y-m-01')))!=)
{
$diffdays=-date('w',strtotime(date('Y-m-01')));
}
else{
$count++;
}
$startdate =strtotime(date('Y-m-01')."+".$diffdays."day");
while (True)
{
if ($thisy!=intval(date('m',$startdate)))
{
break;
}
echo date('Y-m-d',$startdate)."\n";
$startdate = strtotime(date('Y-m-d',strtotime(date('Y-m-d',$startdate)."+7 day")));
//
}

结果

--
--
--
--
--
  • 类版本---date()的参数可以是‘2019-09-20’这样的字符串,如同date('2019-09-20')或者是strtotime返回的整型数如同date('Y-m-d',strtotime('2019-09-20))
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();
echo "时间戳:".date('Y-m-d',$this->firstday)."\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;
}
}
$mycal = new mycalendar(,);
var_dump($mycal->addwday());

结果:

时间戳:2019-10-01
2019-10-06
2019-10-13
2019-10-20
2019-10-27
array(4) {
  [0]=>
  string(10) "2019-10-06"
  [1]=>
  string(10) "2019-10-13"
  [2]=>
  string(10) "2019-10-20"
  [3]=>
  string(10) "2019-10-27"
}
  • 计算月末最后一天
echo date('Y-m-d',strtotime(date('2019-10-01')."+1 month -1 day"));

输出结果:

--
  • 注意!对于日期计算一定要,正确的使用参数,否则将会出错
$lastday = strtotime(date('Y-m-d',$this->time)."+1 day");#正确
$lastday = strtotime(date($this->time)."+1 day");#错误,这样会返回1970-01-01

用strtotime()和date()函数算出2019年9月的周日日期的更多相关文章

  1. 一个js函数算出任意位数的水仙花数

    一个算出任意位数的水仙花数的函数如下: var arr =[]; /*更改num确定取值范围*/ for(var num = 100; num <= 9999;num++){ /*多位数版本*/ ...

  2. javascript基础程序(算出一个数的平方值、算出一个数的阶乘、输出!- !- !- !- !- -! -! -! -! -! 、函数三个数中的最大数)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. [PHP] 重回基础(date函数和strtotime函数)

    date():格式化一个本地时间或者日期,当前时间 2016年5月13日 15:19:49 使用函数date(),输出当前是月份中的第几天,参数:String类型 d 例如:echo date(&qu ...

  4. PHP date()函数详解

    date (PHP 4, PHP 5) date - 格式化一个本地时间/日期 说明¶ string date ( string $format [, int $timestamp ] ) 返回将整数 ...

  5. PHP 格式化显示时间 date() 函数【转】

    date() 函数 功能:用于格式化时间,返回一个字符串.  语法:string date( string format [, int timestamp] ),其中参数 format 表示时间格式化 ...

  6. oracle date函数

    常用的时间格式 在oracle中有 yyyy-mm-dd hh24:mi:ss  而在Java中有些区别 为yyyy-MM-dd HH:mm:ss 这点还是经常容易模糊的.相信很多人都有过统计某些数据 ...

  7. 【夯实PHP基础】PHP的date函数

    本文地址 原文地址 提纲: 1. 引言 2. 代码示例 3. 参考资料 1. 引言 今天看到一段代码 $timeNew = date('n月j日', strtotime($oldTime)); 感觉有 ...

  8. php date函数 参数详细

    time()在PHP中是得到一个数字,这个数字表示从1970-01-01到现在共走了多少秒,很奇怪吧 不过这样方便计算, 要找出前一天的时间就是 time()-60*60*24; 要找出前一年的时间就 ...

  9. [R]R下as.Date()函数的坑

    问题描述: 在本地使用as.Date()函数从POSIXct类型中提取date时,出现了日期不一致的错误.导致处理数据时,总是出问题. 还好被领导发现数据有误,不然这个bug不知道还要潜伏多久.尽管如 ...

随机推荐

  1. 乐字节Java变量与数据结构之二:Java常量与变量

    大家好,小乐又来给大家讲述Java基础知识.上次说了乐字节Java变量与数据类型之一:Java编程规范,关键字与标识符,这次将接着往下说,谈谈Java常量与变量. 1.常量 1).定义 在程序执行的过 ...

  2. K8S从入门到放弃系列-(9)kubernetes集群之kubelet部署

    摘要: Kubelet组件运行在Node节点上,维持运行中的Pods以及提供kuberntes运行时环境,主要完成以下使命: 1.监视分配给该Node节点的pods 2.挂载pod所需要的volume ...

  3. SQL,NoSQL和NewSQL

    一:概念 SQL(Structured Query Language):数据库,指关系型数据库.主要代表:SQL Server.Oracle.MySQL.PostgreSQL. NoSQL(Not O ...

  4. Erlang:[笔记一,构建工具rebar之编译]

    Rebar概述 Rebar是一款Erlang构建工具,使用它可以方便的编译,测试erlang程序和打包erlang发行版本.Rebar其实是一个独立的erlang脚本,默认情况下,Rebar会按照Er ...

  5. docker 的常用命令汇总

  6. S03_CH09_DMA_4_Video_Switch视频切换系统

    S03_CH09_DMA_4_Video_Switch视频切换系统 9.1概述 本例程详细创建过程和本季课程第一课<S03_CH01_AXI_DMA_LOOP 环路测试>非常类似,因此如果 ...

  7. 关于财务YT知识点

    1 YT 将今年剩余的未花完的money做YT,生成一个YT号,用在下一年使用的机制. 2 生成YT的方式 2.1 PR生成YT 2.2 PO生成YT 2.3 TR生成YT 2.4 预算直接生成YT ...

  8. 利用Filter和HttpServletRequestWrapper实现请求体中token校验

    先说一下项目的背景,系统传参为json格式,token为其中一个必传参数,此时如果在过滤器中直接读取request,则后续controller中通过RequestBody注解封装请求参数是会报stre ...

  9. (三)Spring框架之事务管理

    一.编程式事务管理 Spring事务管理器的接口是org.springframework.transaction.PlatformTransactionManager,事务管理器接口PlatformT ...

  10. CVE-2019-0213: Apache Archiva Stored XSS

    CVE-2019-0213: Apache Archiva Stored XSS Severity: Low Vendor:The Apache Software Foundation Version ...