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');
改造,返回日期数组
/**
* 获取当月天数
* @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'));
php根据年月获取当月天数。的更多相关文章
- js 根据年月获取当月有多少天_js获取农历日期_及Js其它常用有用函数
//根据年月获取当月有多少天 function getDaysInMonth(year, month) { debugger; //parseInt(number,type)这个函数后面如果不跟第2个 ...
- PHP获取当月天数,获取当月的每天的开始和结束的时间戳,获取当月每号
由于经常要写导单和数据分析功能,所以要获取什么时间的数据,想什么当天,周,年,月之类的时间格式都很好获取.我今天在这里为大家提供的是当月每天的开始和结束的时间格式. 希望能帮到大家!!! # 获取当月 ...
- SQL获取当月天数的几种方法
原文:SQL获取当月天数的几种方法 日期直接减去int类型的数字 等于 DATEADD(DAY,- 数字,日期) 下面三种方法: 1,日期加一个月减去当前天数,相当于这个月最后一天的日期.然后获取天数 ...
- java获取当月天数,指定年月的天数,指定日期获取对应星期 .
package huolongluo.family.util; import java.text.SimpleDateFormat; import java.util.Calendar; import ...
- php获取当月天数及当月第一天及最后一天、上月第一天及最后一天实现方法
1.获取上个月第一天及最后一天. echo date('Y-m-01', strtotime('-1 month')); echo "<br/>"; ...
- php -- 获取当月天数及当月第一天及最后一天、上月第一天及最后一天(备忘)
Learn From :http://www.jxbh.cn/newshow.asp?id=1635&tag=2 //1.获取上个月第一天及最后一天. date('Y-m-01', strto ...
- php获取当月天数及当月第一天及最后一天
1.获取上个月第一天及最后一天. echo date('Y-m-01', strtotime('-1 month')); echo "<br/>"; ech ...
- new Date()相关获取当月天数和当月第一天
var myDate = new Date(); //获取本月第一天周几 var monthFirst = new Date(myDate.getFullYear(), parseInt(myDat ...
- JavaScript 获取当月天数
getDate() 方法可返回月份的某一天.取值范围是1~31 如果是0的话,就返回最后一天.这样就能取得当月的天数了 比如获取16年2月份的天数 var day = new Date(2016,2, ...
随机推荐
- Software Engineering at Google
Google的Fergus Henderson在Software Engineering at Google中介绍了Google的软件工程实践. 软件开发 源码仓库 单一源代码仓库,除了核心配置和安全 ...
- 构造函数=default表示什么?
myClass()=default;//表示默认存在构造函数
- xpath选择器简介及如何使用
xpath选择器简介及如何使用 一.总结 一句话总结:XPath 的全称是 XML Path Language,即 XML 路径语言,它是一种在结构化文档(比如 XML 和 HTML 文档)中定位信息 ...
- 【Demo】HTML5获取地理位置
HTML5获取地理位置简单实例 实例1--获取地理位置的经纬度: <!DOCTYPE html> <html> <head> <meta charset=& ...
- lambda表达式----使用
List<THealthKnowledgeEntity> tHealthKnowledgeList = tHealthKnowledgeService.queryList(query);L ...
- saltstack技术入门与实践
基本原理 SaltStack 采用`C/S`模式,server端就是salt的master,client端就是minion,minion与master之间通过`ZeroMQ`消息队列通信. minio ...
- SurfaceView基本使用--动态画正弦函数
package com.zzw.TestSurfaceView; import android.content.Context; import android.graphics.Canvas; imp ...
- 内存保护机制及绕过方案——利用未启用SafeSEH模块绕过SafeSEH
前言:之前关于safeSEH保护机制的原理等信息,可在之前的博文(内存保护机制及绕过方案中查看). 利用未启用SafeSEH模块绕过SafeSEH ⑴. 原理分析: 一个不是仅包含中间语言(1L)且 ...
- New Concept English three (39)
26w/m 70errors The rough across the plain soon became so bad that we tried to get Bruce to drive bac ...
- Re-install Flyme or Native Google Android on Meizu MX4 Ubuntu (by quqi99)
作者:张华 发表于:2017-06-23 版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明 ( http://blog.csdn.net/quqi99 ) ## ...