php获取本周周一、周日时间,上周周一、周日时间,本月第一天,本月最后一天,上个月第一天,最后一天时间
来源:互联网 发布:sql嵌套select语句 编辑:程序博客网 时间:2024/05/17 08:34
//这个星期的星期一
// @$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).
''
;
0 0
- php获取本周周一、周日时间,上周周一、周日时间,本月第一天,本月最后一天,上个月第一天,最后一天时间
- php获取本周周一、周日时间,上周周一、周日时间,本月第一天,本月最后一天,上个月第一天,最后一天时间
- php获取本周周一、周日时间,上周周一、周日时间,本月第一天,本月最后一天,上个月第一天,最后一天时间
- php获取本周周一、周日时间,上周周一、周日时间,本月第一天,本月最后一天,上个月第一天,最后一天时间
- php获取本周周一、周日时间,上周周一、周日时间,本月第一天,本月最后一天,上个月第一天,最后一天时间
- php本周、本月的第一天、最后一天的时间
- 获取本周第一天/最后一天、本月第一天/最后一天的时间戳
- 本周周一、本月最后一天、本年第一天sql
- Asp.net C# 获取本周上周本月上月本年上年第一天最后一天时间大全
- 【转】Asp.net获取本周上周本月上月本年上年第一天最后一天时间大全
- mysql 根据指定日期取 周一至周日 本月第一天 最后一天
- 日期加天数、字符串类型转date、获取本周第一天、本周最后一天、本月第一天、本月最后一天、上月第一天、上月最后一天时间
- SQL获取本周,上周,本月,上月第一天和最后一天[注:本周从周一到周天]
- java 获取上月、一个月最后一天、周一、周日、本月日期
- java 获取上月、一个月最后一天、周一、周日、本月日期 【转】
- sqlserver时间函数获取本月最后一天
- C#、VB获取本月第一天、本月最后一天
- sql获得本周,本月,本年第一天最后一天
- Android 关于listview
- html5读取本地文件 图片上传 示例代码
- 心然吧十周年,心然给大家的话
- C语言学习之函数
- h.264与AVS
- php获取本周周一、周日时间,上周周一、周日时间,本月第一天,本月最后一天,上个月第一天,最后一天时间
- 嵌入式Linux下面查看gpio使用情况
- Android 监听网络状态+源代码
- Kafka试用记录
- IOS中Segue的使用
- Python基础复习
- html5多文件上传代码
- Git配置SSH非默认端口(22)
- C语言学习之数组及指针