权声明:本文为博主原创文章,未经博主允许不得转载。

  1. //这个星期的星期一
  2. // @$timestamp ,某个星期的某一个时间戳,默认为当前时间
  3. // @is_return_timestamp ,是否返回时间戳,否则返回时间格式
  4. function this_monday($timestamp=0,$is_return_timestamp=true){
  5. static $cache ;
  6. $id = $timestamp.$is_return_timestamp;
  7. if(!isset($cache[$id])){
  8. if(!$timestamp) $timestamp = time();
  9. $monday_date = date('Y-m-d', $timestamp-86400*date('w',$timestamp)+(date('w',$timestamp)>0?86400:-/*6*86400*/518400));
  10. if($is_return_timestamp){
  11. $cache[$id] = strtotime($monday_date);
  12. }else{
  13. $cache[$id] = $monday_date;
  14. }
  15. }
  16. return $cache[$id];
  17. }
  18. //这个星期的星期天
  19. // @$timestamp ,某个星期的某一个时间戳,默认为当前时间
  20. // @is_return_timestamp ,是否返回时间戳,否则返回时间格式
  21. function this_sunday($timestamp=0,$is_return_timestamp=true){
  22. static $cache ;
  23. $id = $timestamp.$is_return_timestamp;
  24. if(!isset($cache[$id])){
  25. if(!$timestamp) $timestamp = time();
  26. $sunday = this_monday($timestamp) + /*6*86400*/518400;
  27. if($is_return_timestamp){
  28. $cache[$id] = $sunday;
  29. }else{
  30. $cache[$id] = date('Y-m-d',$sunday);
  31. }
  32. }
  33. return $cache[$id];
  34. }
  35. //上周一
  36. // @$timestamp ,某个星期的某一个时间戳,默认为当前时间
  37. // @is_return_timestamp ,是否返回时间戳,否则返回时间格式
  38. function last_monday($timestamp=0,$is_return_timestamp=true){
  39. static $cache ;
  40. $id = $timestamp.$is_return_timestamp;
  41. if(!isset($cache[$id])){
  42. if(!$timestamp) $timestamp = time();
  43. $thismonday = this_monday($timestamp) - /*7*86400*/604800;
  44. if($is_return_timestamp){
  45. $cache[$id] = $thismonday;
  46. }else{
  47. $cache[$id] = date('Y-m-d',$thismonday);
  48. }
  49. }
  50. return $cache[$id];
  51. }
  52. //上个星期天
  53. // @$timestamp ,某个星期的某一个时间戳,默认为当前时间
  54. // @is_return_timestamp ,是否返回时间戳,否则返回时间格式
  55. function last_sunday($timestamp=0,$is_return_timestamp=true){
  56. static $cache ;
  57. $id = $timestamp.$is_return_timestamp;
  58. if(!isset($cache[$id])){
  59. if(!$timestamp) $timestamp = time();
  60. $thissunday = this_sunday($timestamp) - /*7*86400*/604800;
  61. if($is_return_timestamp){
  62. $cache[$id] = $thissunday;
  63. }else{
  64. $cache[$id] = date('Y-m-d',$thissunday);
  65. }
  66. }
  67. return $cache[$id];
  68. }
  69. //这个月的第一天
  70. // @$timestamp ,某个月的某一个时间戳,默认为当前时间
  71. // @is_return_timestamp ,是否返回时间戳,否则返回时间格式
  72. function month_firstday($timestamp = 0, $is_return_timestamp=true){
  73. static $cache ;
  74. $id = $timestamp.$is_return_timestamp;
  75. if(!isset($cache[$id])){
  76. if(!$timestamp) $timestamp = time();
  77. $firstday = date('Y-m-d', mktime(0,0,0,date('m',$timestamp),1,date('Y',$timestamp)));
  78. if($is_return_timestamp){
  79. $cache[$id] = strtotime($firstday);
  80. }else{
  81. $cache[$id] = $firstday;
  82. }
  83. }
  84. return $cache[$id];
  85. }
  86. //这个月的第一天
  87. // @$timestamp ,某个月的某一个时间戳,默认为当前时间
  88. // @is_return_timestamp ,是否返回时间戳,否则返回时间格式
  89. function month_lastday($timestamp = 0, $is_return_timestamp=true){
  90. static $cache ;
  91. $id = $timestamp.$is_return_timestamp;
  92. if(!isset($cache[$id])){
  93. if(!$timestamp) $timestamp = time();
  94. $lastday = date('Y-m-d', mktime(0,0,0,date('m',$timestamp),date('t',$timestamp),date('Y',$timestamp)));
  95. if($is_return_timestamp){
  96. $cache[$id] = strtotime($lastday);
  97. }else{
  98. $cache[$id] = $lastday;
  99. }
  100. }
  101. return $cache[$id];
  102. }
  103. //上个月的第一天
  104. // @$timestamp ,某个月的某一个时间戳,默认为当前时间
  105. // @is_return_timestamp ,是否返回时间戳,否则返回时间格式
  106. function lastmonth_firstday($timestamp = 0, $is_return_timestamp=true){
  107. static $cache ;
  108. $id = $timestamp.$is_return_timestamp;
  109. if(!isset($cache[$id])){
  110. if(!$timestamp) $timestamp = time();
  111. $firstday = date('Y-m-d', mktime(0,0,0,date('m',$timestamp)-1,1,date('Y',$timestamp)));
  112. if($is_return_timestamp){
  113. $cache[$id] = strtotime($firstday);
  114. }else{
  115. $cache[$id] = $firstday;
  116. }
  117. }
  118. return $cache[$id];
  119. }
  120. //上个月的第一天
  121. // @$timestamp ,某个月的某一个时间戳,默认为当前时间
  122. // @is_return_timestamp ,是否返回时间戳,否则返回时间格式
  123. function lastmonth_lastday($timestamp = 0, $is_return_timestamp=true){
  124. static $cache ;
  125. $id = $timestamp.$is_return_timestamp;
  126. if(!isset($cache[$id])){
  127. if(!$timestamp) $timestamp = time();
  128. $lastday = date('Y-m-d', mktime(0,0,0,date('m',$timestamp)-1, date('t',lastmonth_firstday($timestamp)),date('Y',$timestamp)));
  129. if($is_return_timestamp){
  130. $cache[$id] = strtotime($lastday);
  131. }else{
  132. $cache[$id] =  $lastday;
  133. }
  134. }
  135. return $cache[$id];
  136. }
  137. echo '本周星期一:'.this_monday(0,false).'';
  138. echo '本周星期天:'.this_sunday(0,false).'';
  139. echo '上周星期一:'.last_monday(0,false).'';
  140. echo '上周星期天:'.last_sunday(0,false).'';
  141. echo '本月第一天:'.month_firstday(0,false).'';
  142. echo '本月最后一天:'.month_lastday(0,false).'';
  143. echo '上月第一天:'.lastmonth_firstday(0,false).'';
  144. echo '上月最后一天:'.lastmonth_lastday(0,false).'';

php获取本周周一、周日时间,上周周一、周日时间,本月第一天,本月最后一天,上个月第一天,最后一天时间的更多相关文章

  1. sql 获取本周周一和周日

    版本1.0(获取周日存在问题,请勿使用,仅用于引以为戒) 存在问题,获取周日的时候,当当前时间正好是周日,会获取下一周的周日,而非本周周日. ,)),) ),, ,)),) 版本2.0 看到版本1.0 ...

  2. SQL获取本周,上周,本月,上月第一天和最后一天[注:本周从周一到周天]

    DECLARE @ThisWeekStartTime NVARCHAR(100),@ThisWeekEndTime NVARCHAR(100),--本周 @LastWeekStartTime NVAR ...

  3. js获取本周、上周的开始结束时间

    这两天在做一个报表体统,其中涉及到了一个根据本周,上周,本月,上月的时间来进行查询的问题,在这个我就教一下大家怎么实现,大家如果有更好的实现方法的,我也希望大家能说出来,我们交流交流. 首先呢,我写了 ...

  4. js获取选中日期的当周的周一和周日

    js获取选中日期的当周的周一和周日 第一种方法(推荐): function getWeekStr(str) { // 将字符串转为标准时间格式 str2 = Date.parse(str); let ...

  5. C#获取本周、上周、本月、上月、本季度、上季度、本年、上一年起始时间和结束时间

    /// 取得某月的第一天 /// </summary> /// <param name="datetime">要取得月份第一天的时间</param&g ...

  6. SQL获取本周,上周,本月,上月的开始时间和结束时间

    ),),--本周 ),),--上周 ),),--本月 ),),--上月 ),),--近半年 ),)--近一年 ), ,, ),)--本周开始时间 ), ,, ),)--本周结束时间 ),,, ),)- ...

  7. C#获取本周周一的日期

    /// <summary> /// 获取本周的周一日期 /// </summary> /// <returns></returns> public st ...

  8. 【HANA系列】SAP HANA SQL获取本周的周一

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA SQL获取本周 ...

  9. Asp.net C# 获取本周上周本月上月本年上年第一天最后一天时间大全

    DateTime dt = DateTime.Now; int weeknow = Convert.ToInt32(DateTime.Now.DayOfWeek); ) * weeknow + ; D ...

随机推荐

  1. [HMLY]14.对iOS开发中使用MVVM的理解和使用(初级)

    前言 MVVMDemo 之前几个月一直在学习react-native,它的组件化开发真的是很棒,控件和页面的组件化在开发中可以很好的复用,节省开发时间.在那个时候还不知道react-native开发用 ...

  2. Jquery datepicker 时间插件使用 js 时间相加,相减

    $(document).ready(function(){ //输入框事件 $('#probation').bind('input propertychange', function() { var ...

  3. Vim快捷键大全

    vi(vim)是上Linux非常常用的编辑器,很多Linux发行版都默认安装了vi(vim).vi(vim)命令繁多但是如果使用灵活之后将会大大提高效率.vi是"visual interfa ...

  4. 2016 ACM/ICPC Asia Regional Qingdao Online 1001 I Count Two Three

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  5. JavaScript - 平稳退化

    JavaScript使用window对象的open()方法来创建新的浏览器窗口.这个方法有三个参数:window.open(url,name,features)这三个参数都是可选的.1.第一个参数是想 ...

  6. [Q]自定义快捷键

    打开CAD批量打图精灵主界面可以使用以下三个命令其一:“QuickPlot”.“QPlot”.“QP”.“PP”,其中“PP”可以更改, 方法如下:进入AutoCAD传统界面,点“工具”-“自定义”- ...

  7. python3 获取阿里云ECS 实例及监控的方法

    #!/usr/bin/env python3.5 # -*- coding:utf8 -*- try: import httplib except ImportError: import http.c ...

  8. VMware安装ubuntu,通过/mnt/hgfs 挂载共享Windows系统文件夹

    网上各种相关的配置说明,但是都没一个完整的,在这里楼主结合实战亲测,这一整套包含各种情况 1.安装VMware tools 2.解压到任意一个文件夹 tar -xzvf VMwareTools**** ...

  9. 图像处理_imgproc笔记(1)

    图像处理_滤波器 (1)图像的平滑处理 图像的平滑也称模糊,平滑处理需要一个滤波器,最常用的滤波器就是线性滤波器,线性滤波器的输出像素值是g(x,y),是输入像素值是  f(x,y)的加权和:    ...

  10. Asp.net简单代码设置GridView自适应列宽不变形

    动态绑定的GridView由于列数不固定,而列又太多,是要自定设置gridView的宽度 //在GridView的行数据绑定完的事件中设置 protected void gvObjectList_Ro ...