0

我想过滤我的输出:

07-02-13 20:08:41   test11@gmail.com
07-02-13 20:09:41   test11@gmail.com
07-02-13 20:21:25   hottie@gmail.com
07-02-13 20:56:51   ugly@gmail.com
07-02-13 21:42:37   selma532@gmail.com
07-02-13 22:09:11   blalbla421@gmail.com

我想过滤我的输出,所以在 2 分钟内出现的电子邮件必须做一些事情。到目前为止,这是我的“过滤器代码”。但它不起作用。我究竟做错了什么?

strtotime('-2 minutes"', strtotime(date('d-m-y H:i:s', $filter['created'])
4

1 回答 1

1

The problem is that you date format is ambiguous. Does 07-02-13 mean February 7th 2013 (ie today) or does it mean July 2nd 2013 (US standard format), or does it mean February 13th 2007 (big-endian format) or what?

I would suggest rewriting your code so that it produces timestamps in big-endian format,
that is Y-m-d H:i:s. In this format, you can compare them as if they were strings, so all you'd have to do is:

$two_minutes_ago = date("Y-m-d H:i:s",strtotime("-2 minutes"));
if( $value_to_test > $two_mintes_ago) {
    do_something();
}
于 2013-02-07T22:58:33.563 回答