使用strtotime()在php中计算相对日期 [英] Computing relative dates in php using strtotime()

查看:30
本文介绍了使用strtotime()在php中计算相对日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种可靠的方法来返回当前周指定工作日(例如星期一")的完整日期.

由于今天是 2012 年 6 月 13 日星期三,我预计 <?php echo date("Y-m-d", strtotime('Mon this week'));?> 导致 2012-06-11,但 php 返回 2012-06-18 就好像它解释了 本周strong> 表示下周.为什么会出现这种行为,我应该怎么做?

谢谢.

--杰夫

解决方案

date( 'Ym-d', strtotime( 'last Monday', strtotime( 'Sunday' ) ) );

这将搜索下一个星期日之前的星期一.

I'm looking for a reliable way to return the full date of a specified weekday (e.g. "Mon") for the current week.

Since today is Wednesday, June 13, 2012, I expected <?php echo date("Y-m-d", strtotime('Mon this week')); ?> to result in 2012-06-11, but instead php returns 2012-06-18 as though it interprets this week as meaning next week. Why this behavior and what should I be doing?

Thanks.

--Jeff

解决方案

date( 'Y-m-d', strtotime( 'last Monday', strtotime( 'Sunday' ) ) );

This searches for the Monday previous to the next Sunday.

这篇关于使用strtotime()在php中计算相对日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆