Home > Backend Development > PHP Tutorial > 日期函数解决办法

日期函数解决办法

WBOY
Release: 2016-06-13 11:50:42
Original
956 people have browsed it

日期函数
以php实现 一个函数,使它可以根据传入的日期字符串(如2012-03-02)来返回那一天所在周是从哪一天到哪一天?留意跨月和闰年、闰月的情况。
------解决方案--------------------

print_r(between('2012-03-02'));<br /><br />function between($s) {<br />  $t = is_numeric($s) ? $s : strtotime($s);<br />  $w = date('w', $t);<br />  return array(<br />    date('Y-m-d', strtotime("-$w day",$t)),<br />    date('Y-m-d', strtotime((6-$w).' day', $t))<br />  );<br />}
Copy after login
Array
(
    [0] => 2012-02-26
    [1] => 2012-03-03
)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template