热搜:NVER node 开发 php

日期函数

2024-09-03 12:15:01
日期函数

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


回复讨论(解决方案)

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

谢谢版主啊!!!