php输出12个月,php获取12个月内的开始时间和结束时间
$currentTime = time();
$cyear = floor(date("Y",$currentTime));
$cMonth = floor(date("m",$currentTime));
for($i=0;$i<6;$i++){
$nMonth = $cMonth-$i;
$cyear = $nMonth == 0 ? ($cyear-1) : $cyear;
$nMonth = $nMonth <= 0 ? 12+$nMonth : $nMonth;
$date = $cyear."-".$nMonth."-1";
$firstday = date('Y-m-01', strtotime($date));
$lastday = date('Y-m-t', strtotime($date));
echo $cyear."年".$nMonth."月";
echo "第一天:".$firstday;
echo "最后一天:".$lastday,"";
}
最好用的
$date = '2018-07';
$month_begin_time = strtotime($date);
$month_end_time = strtotime($date.'+1 month') -1;
$day_begin_time = $month_begin_time;
$day_end_time = $day_begin_time + 24*3600 - 1;
while ($day_begin_time < $month_end_time) {
# code...
echo date('Y-m-d', $day_end_time);
echo "";
$day_begin_time += 24*3600;
$day_end_time += 24*3600;
}
错误姿势
$first = time();
$months = array();
for ($i = 5; $i >= 0; $i--) s
array_push($months, date('Y-m', strtotime("-$i month", $first)));
}
print_r(months);
会出现两个相同的月份
php输出12个月,php获取12个月内的开始时间和结束时间相关推荐
- oracle旬统计,oracle获取上一旬的开始时间和结束时间的函数
-- 获取上旬开始时间 create or replace function fd_lastxunstart(rq in date) return string is refstr varchar2( ...
- oracle旬统计,oracle获取上一旬的开始时间和结束时间的实现函数
-- 获取上旬开始时间 create or replace function fd_lastxunstart(rq in date) return string is refstr varchar2( ...
- php 获取季度时间段,php 取开始时间和结束时间所跨越的全部季度时间
/** 由起止日期算出其中所跨的季度 和各季度开始结束时间 * params * $st:开始日期 Y-m-d格式 * $et:结束日期 Y-m-d格式*/ function getQuarter($ ...
- 快速获取一天的开始时间和结束时间
前言 在日常开发中,我们经常需要获取某一天的开始时间和结束时间,然后再去做一些逻辑处理.这里提供两种demo. java8之前 这种是采用手动设置日期的时分秒为需要的格式,具体代码如下 @Testpu ...
- java获取一年的周数、单周开始时间与结束时间、一年所有周开始时间与结束时间、月开始时间与结束时间
java获取一年的周数.单周开始时间与结束时间.一年所有周开始时间与结束时间.月开始时间与结束时间 package com.frgk.produce.util;import org.springfra ...
- JAVA 获取某天、某周、某月、某年的开始时间和结束时间
[JAVA 获取某天.某周.某月.某年的开始时间和结束时间] 原文参考地址:JAVA 获取某天.某周.某月.某年的开始时间和结束时间 import java.util.Calendar; import ...
- js获取下月时间_JS获取上月,本月,下月的开始时间与结束时间
``###JS获取上月,本月,下月的开始时间与结束时间(记录) //获取当天的时间 function getToday() { var date = new Date(); return date . ...
- 获取年、季度、月份的开始时间和结束时间,到时分秒
根据传入的日期获取开始时间和结束时间,到时分秒级别 如果不要时分秒,SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd" ...
- Java获取指定年月的开始时间和结束时间
文章目录 Java获取指定年月的开始时间和结束时间 Java获取指定年月的开始时间和结束时间 // 获取指定年指定月的开始天数和结束天数public static Map<String,Date ...
最新文章
- 齐博cms 7.0 漏洞分析
- 认识人和鱼的AI,能识别美人鱼吗?阿里CVPR论文试用因果推理方法解答
- 画原型时需要注意什么?
- http和https的区别和联系
- 1.App瘦身经验总结
- 【北斗】北斗卫星导航系统(BDS)介绍
- java定义一个course类,求指教定义一个学生类 ,大学生小学生,定义一个选课接口...
- 华为杨超斌:5G千元机有望明年底上市
- 当我答出了springboot只有5%人涉足的领域,面试官一脸诧异
- 2021-2027全球及中国LXP平台行业研究及十四五规划分析报告
- C# 按层选择 AutoCAD二次开发
- ROS中gazebo工具学习(使用gazebo加载机器人模型)
- 串口通信校验方式(even,odd,space,mark)UART数据波形分析
- python 微信公众号接口之上传图片素材
- Ubuntu 禁用Guest用户
- java pdf转图片原理_pdf转图片程序(java实现)
- 2021全球程序员收入报告出炉!字节高级码农年薪274万元排第5【文末送5本书】...
- Qt在线安装器下载快的办法
- 基于多模型融合的用户画像分析统计方法研究
- h5页面如何预览excel文件_kintone excel预览插件
热门文章
- 工作中 99% 会用到的 Git 命令
- ReactNative环境搭建扩展篇——安装后报错解决方案
- Everything是如何搜索的
- 在新建FileInputStream时使用当前相对路径或者绝对路径作为参数的问题
- csapp bufbomb实验
- coroutine资源索引
- Can‘t find a suitable configuration file in this directory or any parent. 报错解决错误
- 全网最详细 Python如何读取NIFTI格式图像(.nii文件)和 .npy格式文件和pkl标签文件内容
- 初探EntityFramework——实体类结构映射
- h5禁用浏览器下载视频_Flash正式被全球禁用,只有中国版还活着