date()函数:

  PHP date()  参考:https://www.hi-docs.com/php/date.html

  Linux date()参考:http://www.cnblogs.com/barrychiao/archive/2012/10/08/2715808.html

获取某时间段以周、月、季度为粒度的时间段数组

 function getdays($day){//指定天的周一和周天
$lastday=date('Y-m-d',strtotime("$day Sunday"));
$firstday=date('Y-m-d',strtotime("$lastday -6 days"));
return array($firstday,$lastday);
}
function getmonths($day){//指定月的第一天和最后一天
$firstday = date('Y-m-01',strtotime($day));
$lastday = date('Y-m-d',strtotime("$firstday +1 month -1 day"));
return array($firstday,$lastday); }
/**
* 输入开始时间,结束时间,粒度(周,月,季度)
* @param 参数一:开始时间
* @param 参数二:结束时间
* @param 参数三:粒度(周,月,季度)
* @return 时间段字符串数组
*/
function get_ld_times($st,$et,$ld){
if($ld=='周'){
$timeArr=array();
$t1=$st;
$t2=getdays($t1)['1'];
while($t2<$et || $t1<=$et){//周为粒度的时间数组
$timeArr[]=$t1.','.$t2;
$t1=date('Y-m-d',strtotime("$t2 +1 day"));
$t2=getdays($t1)['1'];
$t2=$t2>$et?$et:$t2;
}
return $timeArr;
}else if($ld=='月'){
$timeArr=array();
$t1=$st;
$t2=getmonths($t1)['1'];
while($t2<$et || $t1<=$et){//月为粒度的时间数组
$timeArr[]=$t1.','.$t2;
$t1=date('Y-m-d',strtotime("$t2 +1 day"));
$t2=getmonths($t1)['1'];
$t2=$t2>$et?$et:$t2;
}
return $timeArr;
}else if($ld=='季度'){
$tStr=explode('-',$st);
$month=$tStr['1'];
if($month<=3){
$t2=date("$tStr[0]-03-31");
}else if($month<=6){
$t2=date("$tStr[0]-06-30");
}else if($month<=9){
$t2=date("$tStr[0]-09-30");
}else{
$t2=date("$tStr[0]-12-31");
}
$t1=$st;
$t2=$t2>$et?$et:$t2;
$timeArr=array();
while($t2<$et || $t1<=$et){//月为粒度的时间数组
$timeArr[]=$t1.','.$t2;
$t1=date('Y-m-d',strtotime("$t2 +1 day"));
$t2=date('Y-m-d',strtotime("$t1 +3 months -1 day"));
$t2=$t2>$et?$et:$t2;
}
return $timeArr;
}else{
return array('参数错误!');
}
}

PHP date()获取某时间段以周、月、季度为粒度的时间段数组的更多相关文章

  1. java获取当前时间的年周月季度等的开始结束时间

    import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; /** * Created b ...

  2. java获取当前年、半年、季度、月、日、小时 开始结束时间等

    import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; /** * 获取 当前年.半年 ...

  3. C#根据当前时间获取周,月,季度,年度等时间段的起止时间

    最近有个统计分布的需求,需要按统计本周,上周,本月,上月,本季度,上季度,本年度,上年度等时间统计分布趋势,所以这里就涉及到计算周,月,季度,年度等的起止时间了,下面总结一下C#中关于根据当前时间获取 ...

  4. mysql中增加某一时间段内的时间数据(包含:时间、年、月、日、第几周、季度)

    创建表dim_date: create table `dim_date` ( `year` int (20), `month` int (20), `day` int (20), `week` int ...

  5. Flex自定义组件开发之日周月日期选择日历控件

    原文:Flex自定义组件开发之日周月日期选择日历控件         使用过DateField的我们都知道,DateField 控件是用于显示日期的文本字段,字段右侧带有日历图标.当用户在控件边框内的 ...

  6. [转] Js获取 本周、本月、本季度、本年、上月、上周、上季度、去年时间段

    /** * 针对时间的工具类 */ var DateTimeUtil = function () { /*** * 获得当前时间 */ this.getCurrentDate = function ( ...

  7. js 获取每月有几周,根据年月周获取该周从周一到周日的日期等方法

    本文基于react-native 本人在用react-native写一个关于课程表的APP时需要课程表按照日期周期显示,网上查了许多方法,都没有达到自己想要的效果,根据一些方法的参考,再根据自己思维写 ...

  8. PHP获取接下来一周的日期

    //获取接下来一周的日期 function GetWeeks() { $i=0; $weeks=[]; for ($i;$i<=7;$i++){ $month=date('m',time()+8 ...

  9. PHP获取某年第几周的开始日期和结束日期

    http://blog.csdn.net/qq_27080247/article/details/50835956 /** * 获取某年第几周的开始日期和结束日期 * @param int $year ...

随机推荐

  1. Linux下PHP开启Oracle支持(oci8)

    使用php的常见问题是:编译php时忘记加入某扩展,后来想加入扩展,可是由于安装php后又装了一些东西如PEAR等,不想删除文件夹重装,那么此时就须要自己又一次添加某模块支持了,Linux操作系统下能 ...

  2. Leaflet--建设移动设备友好的互动地图

    Leaflet 是一个为建设移动设备友好的互动地图,而开发的现代的.开源的 JavaScript 库.它是由 Vladimir Agafonkin 带领一个专业贡献者团队开发,尽管代码仅有 33 KB ...

  3. Android 经常使用工作命令mmm,mm,m,croot,cgrep,jgrep,resgrep,godir

    官方定义: Invoke ". build/envsetup.sh" from your shell to add the following functions to your ...

  4. thinkphp5项目--个人博客(二)

    thinkphp5项目--个人博客(二) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  5. Word histogram

    Here is a program that reads a file and builds a histogram of the words in the file: process_file lo ...

  6. POJ 1274 二分图匹配

    匈牙利算法 裸题 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...

  7. HBase框架基础(四)

    * HBase框架基础(四) 上一节我们介绍了如何使用HBase搞一些MapReduce小程序,其主要作用呢是可以做一些数据清洗和分析或者导入数据的工作,这一节我们来介绍如何使用HBase与其他框架进 ...

  8. miniUI-SelectGrid 弹出选择表格-翻页选中

    介绍 mini中已经给出 弹出表格的里例子 :MiniUi版本 但是在应用过程中遇到写小问题就是没有办法翻页后一并连之前翻页选中的一起提交 以下是解决方案 正文 下面首先介绍  JS 代码 //存储已 ...

  9. Struts2+MySQL登录注册

    下载地址:http://download.csdn.net/detail/qq_33599520/9777172 项目结构图: 代码: package com.mstf.action; import ...

  10. XML字符串解析实体类方法

    /// <summary> /// XML字符串解析实体类方法 /// </summary> public class StringXML { public StringXML ...