我有一个包含事件的星期日历,并且希望用户无法添加过去几天的事件。所以我特林使用函数那样:检查给定日期是否过去
if(strtotime($this->day) < time()){ // date format is YYYY-MM-DD
// date is past
}else{
// date is not past
}
它似乎工作得很好,但它认为今天的日期为过去的一天。我究竟做错了什么?
我有一个包含事件的星期日历,并且希望用户无法添加过去几天的事件。所以我特林使用函数那样:检查给定日期是否过去
if(strtotime($this->day) < time()){ // date format is YYYY-MM-DD
// date is past
}else{
// date is not past
}
它似乎工作得很好,但它认为今天的日期为过去的一天。我究竟做错了什么?
时间戳从不包含日期,但始终下降到当前秒。将在今天的日期返回0:00
,而您正在比较它与现在的比较,如11:12
。
您可以使用strtotime("$this->day 12:59:59pm");
(如果格式为$this->day
允许)或明天使用的时间戳。
if(strtotime($this->day) < mktime(0, 0, 0)){
// date is past
} else {
// date is not past
}
或者,使用'的strtotime($这个 - >天)
谢谢你!这种方式很好! – Luciano 2010-07-21 09:18:04