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 ...
随机推荐
- Santa Claus and a Palindrome
Santa Claus and a Palindrome 题目链接:http://codeforces.com/contest/752/problem/D 贪心 很自然地,可以想到,若subS不是回文 ...
- openssh-clients(CentOS 7 自带的SSH客户端)
OpenSSH 有自带的服务端 openssh-server(sshd服务) 和 客户端 openssh-clients(ssh命令),平时使用SSH远程登陆Linux都是在本地Windows上使用P ...
- 【1】Hover 效果收集
各种 hover 效果 github repository>> git 仓库 1. 背景图的 hover 效果 原页面>> githubSite>>
- Jquery Easyui与Jquery Bootstrap(Metronic Bootstrap)的简单比较
1,通常来看WEB前端用 bootstrap 比较好,后台用EASYUI比较好.Easyui适合工厂企业的管理系统如ERP,CRM之类的,Bootstrap适用于多屏跨设备浏览. 简言之,一个适合上班 ...
- java error:编码gbk的不可映射字符
解决方法: javac -encoding UTF-8 XX.java
- 【安装】beautifulsoup4—美丽汤的安装
beautifulsoup俗称美丽汤,是用来爬虫用的,大家可以到这个网址去下载.注意,要根据对应的python版本 来下载. 下载传送: https://pypi.python.org/pypi/be ...
- WEB典型应用
- CodeForces 667C Reberland Linguistics
$dp$. 题意中有一个词组:$in$ $a$ $row$,是连续的意思.... 因此这题只要倒着$dp$一下就可以了.$f[i][0]$表示从$i$位置往后割两个能否割,$f[i][1]$表示从$i ...
- Mysq 5.7l服务无法启动,没有报告任何错误
昨天系统崩溃了,然后重装了Mysql 5.7 安装步骤和遇到问题及解决方案. 去官网下载Mysql 5.7的解压包(zip),解压到你要安装的目录. 我的安装目录是:D:\Java\Mysql 安装步 ...
- Gentoo双网卡同时启用上内外网
引言:本文配置网络通过 OpenRC/netifrc 方法(net.*scritps)配置. 外网网卡:enp3s4 内网网卡:enp2s0 外网地址(通过路由器) IP: 192.168.1.10 ...