当前位置:首页 > 电脑知识 > 正文内容

这都可以(php获取当前时间)php获取月份,php获取上个月,上上个月的开始时间与结束时间的方法,php获取上个月,上上个月的开始时间与结束时间的方法,

sauo2年前 (2022-09-17)电脑知识46

记录一下利用php脚本获取上个月,上上个月的开始时间与结束时间的方法,下面的示例代码,有需要的可以参考一下。

php 获取上个月,上上个月的开始时间与结束时间

php获取上个月以及上上个月的时间,就需要从当前的时间减去一个月时间段就可以。我们可以使用 php 中的 strtotime 函数,strtotime 函数可以很方便的在一个时间的基码上进行时间的减去与增加,比如减去一个月,减去一天等等。

示例代码:

PHP
//上个月 echo 上个月:.date(Y-m-01, strtotime(-1 month)); echo <br/>; $time = strtotime(-1 month); echo date(Y-m-d H:i:s, mktime(0,0,0,date(m,$time),01,date(Y,$time)) ); //php上个月的开始时间 echo <br/>; echo date(Y-m-d H:i:s, mktime(23,59,59,date(m,$time),date(t,$time),date(Y,$time)) ); //上个月的结束时间 echo <hr>; //上上个月 echo 上上个月:.date(Y-m-01, strtotime(-2 month)); echo <br/>; echo date(Y-m-01, strtotime(-2 month)); $time2 = strtotime(date(Y-m-01, strtotime(-2 month))); echo <br/>; echo date(Y-m-d H:i:s, mktime(0,0,0,date(m,$time2),01,date(Y,$time2)) ); echo <br/>; echo date(Y-m-d H:i:s, mktime(23,59,59,date(m,$time2),date(t,$time2),date(Y,$time2)) ); echo <hr>; //上上上个月 echo 上上上个月:. date(Y-m-01, strtotime(-3 month)); $time3 = strtotime(date(Y-m-01, strtotime(-3 month))); echo <br/>; echo date(Y-m-d H:i:s, mktime(0,0,0,date(m,$time3),01,date(Y,$time3)) ); echo <br/>; echo date(Y-m-d H:i:s, mktime(23,59,59,date(m,$time3),date(t,$time3),date(Y,$time3)) ); // 飞鸟慕鱼博客 feiniaomy.com复制

注意:每个月的结束时间,是按的当月最后一天晚上23点59分59秒来算的。

本文链接:http://blog.sauo.top/?id=298 感谢分享!

分享到:

扫描二维码推送至手机访问。

版权声明:本文由冬眠先生个人博客发布,如需转载请注明出处。

本文链接:http://blog.sauo.top/?id=298

分享给朋友:

“这都可以(php获取当前时间)php获取月份,php获取上个月,上上个月的开始时间与结束时间的方法,php获取上个月,上上个月的开始时间与结束时间的方法,” 的相关文章

深度揭秘(Ubuntu 防火墙设置)ubuntu防火墙配置文件,ubuntu防火墙的安装与设置,ubuntu防火墙的安装与设置,

免费领取腾讯云服务器! ubuntu系统中的防火墙使用的是iptables,而为了方便防火墙的设置ubuntu提供了一个防火墙管理工具ufw.下面这篇文章就说一说关于防火墙管理工具ufw的安装与使用方法。 ubuntu防火墙ufw的安装与设...

新鲜出炉(ubuntu系统与centos系统区别)ubuntu还是centos,centos系统与ubuntu系统的区分,centos系统与ubuntu系统的区分,

免费领取腾讯云服务器! Linux的发行版有很多,而我们经常使用的为centos与ubuntu,下面这篇博文就说说这两个系统的发源与区别。 CentOS CentOS(Community Enterprise Operati...

干货分享(php file_get_contents curl)php file_get_contents post,php file_get_contents(): SSL operation failed with code 1. OpenSSL Error message.....,php file_get_contents(): SSL operation failed with code 1. OpenSSL Error message.....,

免费领取腾讯云服务器! 在调试php脚本代码时,发现使用 file_get_contents() 函数请求HTTPS的网址链接时出现了报错,其报错代码如下面所示“file_get_contents(): SSL operation failed with...

难以置信(php错误日志在哪里)PHP 日志,php设置错误日志的方法,php设置错误日志的方法,

难以置信(php错误日志在哪里)PHP 日志,php设置错误日志的方法,php设置错误日志的方法,

免费领取腾讯云服务器! php设置错误日志需要在php配置文件php.ini中设置,只需要简单的几步设置就可以实现,下面就来详细的说一下。 php设置错误日志的方法 1、打开php的配置文件,php.ini...

不要告诉别人(php求数组交集)php数组取差集,php计算两个数组的交集与差集,php计算两个数组的交集与差集,

免费领取腾讯云服务器! php中计算两个数组之间的交集与差集可以使用 array_intersect() 与 array_diff() 数组处理函数,这两个数组的具体使用方法如下。 php计算两个数组之间的交集 array_...

这都可以?(jquery去掉前后空格)jquery去掉字符串前后空格,jQuery去掉 serialize() 方法中指定的name值,jQuery去掉 serialize() 方法中指定的name值,

免费领取腾讯云服务器! 在修改一个前台表单提交逻辑时,为了不动以前的代码(代码和屎一样),就想着在提交数据时过滤掉form表单中指定的name属性和值,由于表单直接使用jquery中的serialize()方法来获取的form表单的数据,所以就要对 ser...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。