蝙蝠岛资源网 Design By www.hbtsch.com
本文实例讲述了php根据年月获取当月天数及日期数组的方法。分享给大家供大家参考,具体如下:
function get_day( $date )
{
$tem = explode('-' , $date); //切割日期 得到年份和月份
$year = $tem['0'];
$month = $tem['1'];
if( in_array($month , array( 1 , 3 , 5 , 7 , 8 , 01 , 03 , 05 , 07 , 08 , 10 , 12)))
{
// $text = $year.'年的'.$month.'月有31天';
$text = '31';
}
elseif( $month == 2 )
{
if ( $year%400 == 0 || ($year%4 == 0 && $year%100 !== 0) ) //判断是否是闰年
{
// $text = $year.'年的'.$month.'月有29天';
$text = '29';
}
else{
// $text = $year.'年的'.$month.'月有28天';
$text = '28';
}
}
else{
// $text = $year.'年的'.$month.'月有30天';
$text = '30';
}
return $text;
}
echo get_day('2016-8-1');
运行结果为:31
改造,返回日期数组:
/**
* 获取当月天数
* @param $date
* @param $rtype 1天数 2具体日期数组
* @return
*/
function get_day( $date ,$rtype = '1')
{
$tem = explode('-' , $date); //切割日期 得到年份和月份
$year = $tem['0'];
$month = $tem['1'];
if( in_array($month , array( 1 , 3 , 5 , 7 , 8 , 01 , 03 , 05 , 07 , 08 , 10 , 12)))
{
// $text = $year.'年的'.$month.'月有31天';
$text = '31';
}
elseif( $month == 2 )
{
if ( $year%400 == 0 || ($year%4 == 0 && $year%100 !== 0) ) //判断是否是闰年
{
// $text = $year.'年的'.$month.'月有29天';
$text = '29';
}
else{
// $text = $year.'年的'.$month.'月有28天';
$text = '28';
}
}
else{
// $text = $year.'年的'.$month.'月有30天';
$text = '30';
}
if ($rtype == '2') {
for ($i = 1; $i <= $text ; $i ++ ) {
$r[] = $year."-".$month."-".$i;
}
} else {
$r = $text;
}
return $r;
}
var_dump(get_day('2016-8-1','2'));
运行结果如下:
array(31) {
[0]=>
string(8) "2016-8-1"
[1]=>
string(8) "2016-8-2"
[2]=>
string(8) "2016-8-3"
[3]=>
string(8) "2016-8-4"
[4]=>
string(8) "2016-8-5"
[5]=>
string(8) "2016-8-6"
[6]=>
string(8) "2016-8-7"
[7]=>
string(8) "2016-8-8"
[8]=>
string(8) "2016-8-9"
[9]=>
string(9) "2016-8-10"
[10]=>
string(9) "2016-8-11"
[11]=>
string(9) "2016-8-12"
[12]=>
string(9) "2016-8-13"
[13]=>
string(9) "2016-8-14"
[14]=>
string(9) "2016-8-15"
[15]=>
string(9) "2016-8-16"
[16]=>
string(9) "2016-8-17"
[17]=>
string(9) "2016-8-18"
[18]=>
string(9) "2016-8-19"
[19]=>
string(9) "2016-8-20"
[20]=>
string(9) "2016-8-21"
[21]=>
string(9) "2016-8-22"
[22]=>
string(9) "2016-8-23"
[23]=>
string(9) "2016-8-24"
[24]=>
string(9) "2016-8-25"
[25]=>
string(9) "2016-8-26"
[26]=>
string(9) "2016-8-27"
[27]=>
string(9) "2016-8-28"
[28]=>
string(9) "2016-8-29"
[29]=>
string(9) "2016-8-30"
[30]=>
string(9) "2016-8-31"
}
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php日期与时间用法总结》、《PHP数组(Array)操作技巧大全》、《PHP基本语法入门教程》、《PHP运算与运算符用法总结》、《php面向对象程序设计入门教程》、《PHP网络编程技巧总结》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
蝙蝠岛资源网 Design By www.hbtsch.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
蝙蝠岛资源网 Design By www.hbtsch.com
暂无php根据年月获取当月天数及日期数组的方法的评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2025年10月28日
2025年10月28日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]