Heim > Backend-Entwicklung > PHP-Tutorial > PHP获取指定日期所在月的开始日期与结束日期_PHP教程

PHP获取指定日期所在月的开始日期与结束日期_PHP教程

WBOY
Freigeben: 2016-07-20 11:14:58
Original
1333 Leute haben es durchsucht


如下:

<?<span php
</span><span /*</span><span *
* 获取指定日期所在月的开始日期与结束日期
* @param string $date
* @param boolean 为true返回开始日期,否则返回结束日期
* @return array
* @access private
</span><span */</span>
<span private</span> <span function</span> getMonthRange( <span $date</span>, <span $returnFirstDay</span> = <span true</span><span  ) {
</span><span $timestamp</span> = <span strtotime</span>( <span $date</span><span  );
</span><span if</span> ( <span $returnFirstDay</span><span  ) {
</span><span $monthFirstDay</span> = <span date</span>( 'Y-m-1 00:00:00', <span $timestamp</span><span  );
</span><span return</span> <span $monthFirstDay</span><span ;
} </span><span else</span><span  {
</span><span $mdays</span> = <span date</span>( 't', <span $timestamp</span><span  );
</span><span $monthLastDay</span> = <span date</span>( 'Y-m-' . <span $mdays</span> . ' 23:59:59', <span $timestamp</span><span  );
</span><span return</span> <span $monthLastDay</span><span ;
}
}
</span>?>
Nach dem Login kopieren

代码:

<?<span php
</span><span //</span><span  获取指定日期所在星期的开始时间与结束时间</span>
<span function</span> getWeekRange(<span $date</span><span ){
</span><span $ret</span>=<span array</span><span ();
</span><span $timestamp</span>=<span strtotime</span>(<span $date</span><span );
</span><span $w</span>=<span strftime</span>('%u',<span $timestamp</span><span );
</span><span $ret</span>['sdate']=<span date</span>('Y-m-d 00:00:00',<span $timestamp</span>-(<span $w</span>-1)*86400<span );
</span><span $ret</span>['edate']=<span date</span>('Y-m-d 23:59:59',<span $timestamp</span>+(7-<span $w</span>)*86400<span );
</span><span return</span> <span $ret</span><span ;
} by www</span>.jbxue.<span com

</span><span //</span><span  获取指定日期所在月的开始日期与结束日期</span>
<span function</span> getMonthRange(<span $date</span><span ){
</span><span $ret</span>=<span array</span><span ();
</span><span $timestamp</span>=<span strtotime</span>(<span $date</span><span );
</span><span $mdays</span>=<span date</span>('t',<span $timestamp</span><span );
</span><span $ret</span>['sdate']=<span date</span>('Y-m-1 00:00:00',<span $timestamp</span><span );
</span><span $ret</span>['edate']=<span date</span>('Y-m-'.<span $mdays</span>.' 23:59:59',<span $timestamp</span><span );
</span><span return</span> <span $ret</span><span ;
}


</span><span //</span><span  以上两个函数的应用</span>
<span function</span> getFilter(<span $n</span><span ){
</span><span $ret</span>=<span array</span><span ();
</span><span switch</span>(<span $n</span><span ){
</span><span case</span> 1:<span //</span><span  昨天</span>
<span $ret</span>['sdate']=<span date</span>('Y-m-d 00:00:00',<span strtotime</span>('-1 day'<span ));
</span><span $ret</span>['edate']=<span date</span>('Y-m-d 23:59:59',<span strtotime</span>('-1 day'<span ));
</span><span break</span><span ;
</span><span case</span> 2:<span //</span><span 本星期</span>
<span $ret</span>=getWeekRange(<span date</span>('Y-m-d'<span ));
</span><span break</span><span ;
</span><span case</span> 3:<span //</span><span 上一个星期</span>
<span $strDate</span>=<span date</span>('Y-m-d',<span strtotime</span>('-1 week'<span ));
</span><span $ret</span>=getWeekRange(<span $strDate</span><span );
</span><span break</span><span ;
</span><span case</span> 4: <span //</span><span 上上星期</span>
<span $strDate</span>=<span date</span>('Y-m-d',<span strtotime</span>('-2 week'<span ));
</span><span $ret</span>=getWeekRange(<span $strDate</span><span );
</span><span break</span><span ;
</span><span case</span> 5: <span //</span><span 本月</span>
<span $ret</span>=getMonthRange(<span date</span>('Y-m-d'<span ));
</span><span break</span><span ;
</span><span case</span> 6:<span //</span><span 上月</span>
<span $strDate</span>=<span date</span>('Y-m-d',<span strtotime</span>('-1 month'<span ));
</span><span $ret</span>=getMonthRange(<span $strDate</span><span );
</span><span break</span><span ;
}
</span><span return</span> <span $ret</span><span ;
}</span>?>
Nach dem Login kopieren

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440237.htmlTechArticle如下: ? getMonthRange( , = = ( ( = ( 'Y-m-1 00:00:00', = ( 't', = ( 'Y-m-' . . ' 23:59:59', ? 代码: ? getWeekRange( = = ( = ('%u', ['sdate']= ('Y-m-d 00:00:00', -( -1)*8640...
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage