PHP DateTime()类,将一周的第一天更改为星期一

PHP DateTime()类,将一周的第一天更改为星期一,第1张

PHP DateTime()类,将一周的第一天更改为星期

我发现这可行,但是PHP的DateTime类中存在一些不一致之处。

如果出发日期是星期日,那么上一个星期一将不被视为同一周(由此类固定)。但是从星期一开始,下一个星期日被视为同一周。如果他们将来解决此问题,则该类将需要一些补充。

class EuroDateTime extends DateTime {// Override "modify()"public function modify($string) {    // Change the modifier string if needed    if ( $this->format('N') == 7 ) { // It's Sunday and we're calculating a day using relative weeks        $matches = array();        $pattern = '/this week|next week|previous week|last week/i';        if ( preg_match( $pattern, $string, $matches )) { $string = str_replace($matches[0], '-7 days '.$matches[0], $string);        }    }    return parent::modify($string);}}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5152526.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-18
下一篇 2022-11-18

发表评论

登录后才能评论

评论列表(0条)

保存