问题描述
我有一个星期的日历,举行事件,并希望用户不能添加事件在过去几天。所以我正在使用这样的功能:
I have a week calendar that holds events, and want that users can't add events for the past days. So I'm tring to use a function like that:
if( strtotime($this->day) < time() ){ // date format is YYYY-MM-DD
// date is past
}else{
// date is not past
}
似乎工作正常,除了它将今天视为过去一天。我做错了什么?
It seems to works fine, except that it consider today date as a past day. What am i doing wrong?
推荐答案
时间戳记永远不会包含日期,但始终为当前第二个。 strtotime($ this-> day)
将在 0:00
返回今天的日期,而您正在比较你现在可以使用 11:12
。
A timestamp never contains only the date, but is always down to the current second. strtotime($this->day)
is going to return today's date at 0:00
, while you are comparing it against now, say, 11:12
.
你可以使用 strtotime( $ this-> day 12:59:59 pm);
(如果 $ this-> day
的格式允许)使用明天的时间戳。
You could use strtotime("$this->day 12:59:59pm");
(if the format of $this->day
allows for that) or use tomorrow's timestamp.
这篇关于检查给定日期是否过去的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!