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, ...
随机推荐
- js 小复习2
1.数组 findIndex() indexOf() // findIndex()方法返回数组中满足提供的测试函数的第一个元素的索引.否则返回-1. function isBigEnough(ele ...
- angular components
最近写了一套angular 组件,希望大家支持: Github: https://github.com/zhantewei2/ng-ztw webSite:http://39.108.193.57:3 ...
- 公共域名服务DNS 114.114.114.114和8.8.8.8
一.两者的联系 114.114.114.114和8.8.8.8,这两个IP地址都属于公共域名解析服务DNS其中的一部分,而且由于不是用于商业用途的,这两个DNS都很纯净,不用担心因ISP运营商导致的D ...
- Ajax-06 Ajax数据交换格式
1.数据交换格式 服务端返回的数据,在本质上都是字符串,只是原生Ajax 或jQuery Ajax将这些字符串转换为容易理解的各种常用格式. a. Text 文本字符串 b. XML JavaScr ...
- python之单元测试框架—unittest(补充)
一. unittest最核心的四个概念 unittest中最核心的四个概念是:test case,test suite,test runner,test fixture TestCase:一个test ...
- 如何用Tomcat部署前端静态文件
在项目开发的过程中,一些公司经常是前后台分开的,并不是所有的前端文件都在后台项目中,尤其是互联网公司.这时候就需要后端人员单独运行前端文件.怎么用Tomcat部署运行前端静态文件呢? 工具/原料 ...
- nodejs cheerio模块提取html页面内容
nodejs cheerio模块提取html页面内容 1. nodejs cheerio模块提取html页面内容 1.1. 找到目标元素 1.2. 美化文本输出 1.3. 提取答案文本 1.4. 最终 ...
- while for if ---语句和编写计划任务
关于while循环: while do done 例如 1.关于内存的实时操作: (1).vim a.sh (2).输入以下while循环 (3)../a.sh执行脚本 2.自加一的操作: (1).v ...
- 【scala】getter和setter
我们在用Java的时候经常把一些字段定义为private类型来完成封装,这样外界就无法访问. 如果外界访问或者修改该字段的时候,只能通过该字段提供的getter和setter方法来实现. 在Scala ...
- opencv:访问像素
a.使用指针 #include <opencv.hpp> using namespace cv; using namespace std; int main() { //指针访问每个像素并 ...