php获取本周周一、周日时间,上周周一、周日时间,本月第一天,本月最后一天,上个月第一天,最后一天时间
权声明:本文为博主原创文章,未经博主允许不得转载。
- //这个星期的星期一
- // @$timestamp ,某个星期的某一个时间戳,默认为当前时间
- // @is_return_timestamp ,是否返回时间戳,否则返回时间格式
- function this_monday($timestamp=0,$is_return_timestamp=true){
- static $cache ;
- $id = $timestamp.$is_return_timestamp;
- if(!isset($cache[$id])){
- if(!$timestamp) $timestamp = time();
- $monday_date = date('Y-m-d', $timestamp-86400*date('w',$timestamp)+(date('w',$timestamp)>0?86400:-/*6*86400*/518400));
- if($is_return_timestamp){
- $cache[$id] = strtotime($monday_date);
- }else{
- $cache[$id] = $monday_date;
- }
- }
- return $cache[$id];
- }
- //这个星期的星期天
- // @$timestamp ,某个星期的某一个时间戳,默认为当前时间
- // @is_return_timestamp ,是否返回时间戳,否则返回时间格式
- function this_sunday($timestamp=0,$is_return_timestamp=true){
- static $cache ;
- $id = $timestamp.$is_return_timestamp;
- if(!isset($cache[$id])){
- if(!$timestamp) $timestamp = time();
- $sunday = this_monday($timestamp) + /*6*86400*/518400;
- if($is_return_timestamp){
- $cache[$id] = $sunday;
- }else{
- $cache[$id] = date('Y-m-d',$sunday);
- }
- }
- return $cache[$id];
- }
- //上周一
- // @$timestamp ,某个星期的某一个时间戳,默认为当前时间
- // @is_return_timestamp ,是否返回时间戳,否则返回时间格式
- function last_monday($timestamp=0,$is_return_timestamp=true){
- static $cache ;
- $id = $timestamp.$is_return_timestamp;
- if(!isset($cache[$id])){
- if(!$timestamp) $timestamp = time();
- $thismonday = this_monday($timestamp) - /*7*86400*/604800;
- if($is_return_timestamp){
- $cache[$id] = $thismonday;
- }else{
- $cache[$id] = date('Y-m-d',$thismonday);
- }
- }
- return $cache[$id];
- }
- //上个星期天
- // @$timestamp ,某个星期的某一个时间戳,默认为当前时间
- // @is_return_timestamp ,是否返回时间戳,否则返回时间格式
- function last_sunday($timestamp=0,$is_return_timestamp=true){
- static $cache ;
- $id = $timestamp.$is_return_timestamp;
- if(!isset($cache[$id])){
- if(!$timestamp) $timestamp = time();
- $thissunday = this_sunday($timestamp) - /*7*86400*/604800;
- if($is_return_timestamp){
- $cache[$id] = $thissunday;
- }else{
- $cache[$id] = date('Y-m-d',$thissunday);
- }
- }
- return $cache[$id];
- }
- //这个月的第一天
- // @$timestamp ,某个月的某一个时间戳,默认为当前时间
- // @is_return_timestamp ,是否返回时间戳,否则返回时间格式
- function month_firstday($timestamp = 0, $is_return_timestamp=true){
- static $cache ;
- $id = $timestamp.$is_return_timestamp;
- if(!isset($cache[$id])){
- if(!$timestamp) $timestamp = time();
- $firstday = date('Y-m-d', mktime(0,0,0,date('m',$timestamp),1,date('Y',$timestamp)));
- if($is_return_timestamp){
- $cache[$id] = strtotime($firstday);
- }else{
- $cache[$id] = $firstday;
- }
- }
- return $cache[$id];
- }
- //这个月的第一天
- // @$timestamp ,某个月的某一个时间戳,默认为当前时间
- // @is_return_timestamp ,是否返回时间戳,否则返回时间格式
- function month_lastday($timestamp = 0, $is_return_timestamp=true){
- static $cache ;
- $id = $timestamp.$is_return_timestamp;
- if(!isset($cache[$id])){
- if(!$timestamp) $timestamp = time();
- $lastday = date('Y-m-d', mktime(0,0,0,date('m',$timestamp),date('t',$timestamp),date('Y',$timestamp)));
- if($is_return_timestamp){
- $cache[$id] = strtotime($lastday);
- }else{
- $cache[$id] = $lastday;
- }
- }
- return $cache[$id];
- }
- //上个月的第一天
- // @$timestamp ,某个月的某一个时间戳,默认为当前时间
- // @is_return_timestamp ,是否返回时间戳,否则返回时间格式
- function lastmonth_firstday($timestamp = 0, $is_return_timestamp=true){
- static $cache ;
- $id = $timestamp.$is_return_timestamp;
- if(!isset($cache[$id])){
- if(!$timestamp) $timestamp = time();
- $firstday = date('Y-m-d', mktime(0,0,0,date('m',$timestamp)-1,1,date('Y',$timestamp)));
- if($is_return_timestamp){
- $cache[$id] = strtotime($firstday);
- }else{
- $cache[$id] = $firstday;
- }
- }
- return $cache[$id];
- }
- //上个月的第一天
- // @$timestamp ,某个月的某一个时间戳,默认为当前时间
- // @is_return_timestamp ,是否返回时间戳,否则返回时间格式
- function lastmonth_lastday($timestamp = 0, $is_return_timestamp=true){
- static $cache ;
- $id = $timestamp.$is_return_timestamp;
- if(!isset($cache[$id])){
- if(!$timestamp) $timestamp = time();
- $lastday = date('Y-m-d', mktime(0,0,0,date('m',$timestamp)-1, date('t',lastmonth_firstday($timestamp)),date('Y',$timestamp)));
- if($is_return_timestamp){
- $cache[$id] = strtotime($lastday);
- }else{
- $cache[$id] = $lastday;
- }
- }
- return $cache[$id];
- }
- echo '本周星期一:'.this_monday(0,false).'';
- echo '本周星期天:'.this_sunday(0,false).'';
- echo '上周星期一:'.last_monday(0,false).'';
- echo '上周星期天:'.last_sunday(0,false).'';
- echo '本月第一天:'.month_firstday(0,false).'';
- echo '本月最后一天:'.month_lastday(0,false).'';
- echo '上月第一天:'.lastmonth_firstday(0,false).'';
- echo '上月最后一天:'.lastmonth_lastday(0,false).'';
php获取本周周一、周日时间,上周周一、周日时间,本月第一天,本月最后一天,上个月第一天,最后一天时间的更多相关文章
- sql 获取本周周一和周日
版本1.0(获取周日存在问题,请勿使用,仅用于引以为戒) 存在问题,获取周日的时候,当当前时间正好是周日,会获取下一周的周日,而非本周周日. ,)),) ),, ,)),) 版本2.0 看到版本1.0 ...
- SQL获取本周,上周,本月,上月第一天和最后一天[注:本周从周一到周天]
DECLARE @ThisWeekStartTime NVARCHAR(100),@ThisWeekEndTime NVARCHAR(100),--本周 @LastWeekStartTime NVAR ...
- js获取本周、上周的开始结束时间
这两天在做一个报表体统,其中涉及到了一个根据本周,上周,本月,上月的时间来进行查询的问题,在这个我就教一下大家怎么实现,大家如果有更好的实现方法的,我也希望大家能说出来,我们交流交流. 首先呢,我写了 ...
- js获取选中日期的当周的周一和周日
js获取选中日期的当周的周一和周日 第一种方法(推荐): function getWeekStr(str) { // 将字符串转为标准时间格式 str2 = Date.parse(str); let ...
- C#获取本周、上周、本月、上月、本季度、上季度、本年、上一年起始时间和结束时间
/// 取得某月的第一天 /// </summary> /// <param name="datetime">要取得月份第一天的时间</param&g ...
- SQL获取本周,上周,本月,上月的开始时间和结束时间
),),--本周 ),),--上周 ),),--本月 ),),--上月 ),),--近半年 ),)--近一年 ), ,, ),)--本周开始时间 ), ,, ),)--本周结束时间 ),,, ),)- ...
- C#获取本周周一的日期
/// <summary> /// 获取本周的周一日期 /// </summary> /// <returns></returns> public st ...
- 【HANA系列】SAP HANA SQL获取本周的周一
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA SQL获取本周 ...
- Asp.net C# 获取本周上周本月上月本年上年第一天最后一天时间大全
DateTime dt = DateTime.Now; int weeknow = Convert.ToInt32(DateTime.Now.DayOfWeek); ) * weeknow + ; D ...
随机推荐
- ext3学习小结
先介绍一下ext3和ext4的一些区别吧,初看ext4相对于ext3源码还是有很多不同的,ext4加入的define和create两个强大的类,ext4为了让源码容易看,特意将所有的类进行了defin ...
- Oracle笔记(1) 简单查询、限定查询、数据的排序
Oracle笔记(四) 简单查询.限定查询.数据的排序 一.简单查询 SQL(Structured Query Language) 结构化查询语言,是一种数据库查询和程序设计语言,用于存取数据以及 ...
- 简单字符串匹配 Brute
/* 很简单 模式匹配的Brute-Force算法 Brute-Force算法实现模式匹配的思想是:从主串s=”s0s1…sn-1”的第一个字符开始和模式串t=”t0t1…tn-1”的第一个字符比较, ...
- linux看代码方法和建议
http://blog.csdn.net/lxl584685501/article/details/46803077
- Python将列表中的string元素进行类型转换
例如 将 a=['1','2.0','3L'] 转换为 a=[1,2.0,3L] 只需 map(eval,['1','2.0','3L']) 即可 eval(expression[, globals[ ...
- Ubuntu下Git的使用之创建版本库
创建版本库 什么是版本库呢?版本库又名仓库,英文名repository,你可以简单理解成一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改.删除,Git都能跟踪,以便任何时刻都可以 ...
- [Q]无法卸载怎么办
正确卸载CAD批量打图精灵的方法是进入操作系统,“控制面版”,然后运行“添加和删除程序”,找到CAD批量打图精灵,选“更改/删除”,按照提示操作,即可进行卸载. 若使用强制卸载工具(如360等)卸载可 ...
- 《JavaScript DOM编程艺术》读书笔记
这是自己JS入门的一本书,反复看过几遍,作者的文笔风趣,阅读起来不枯燥也显轻松~ 本书从JS简史讲到基础语法到DOM,再以一个图片库案例为主线,讲如何运用JS来实现想要的动效,同时对已写案例进行兼容优 ...
- 366. Find Leaves of Binary Tree C#
Example:Given binary tree 1 / \ 2 3 / \ 4 5 Returns [4, 5, 3], [2], [1]. Explanation: 1. Removing th ...
- sqlserver负载均衡
http://www.cnblogs.com/gaizai/p/3644510.html