2017-06-16 62 views

回答

1

简单使用的strtotime()函数

http://php.net/manual/en/function.strtotime.php

if(strtotime('Friday 19 may 2017') < strtotime('now')) { 
    echo 'do something'; 
} 

或(编辑,因为BenM评论)

if(strtotime('Friday 19 may 2017') < time()) { 
    echo 'do something'; 
} 
+1

'strtotime('now')'==='time()'。 – BenM

+0

谢谢Raymond! – Bas

1

使用DateTime类PHP:

$date = new DateTime('2017-05-19 00:00:00'); 
$now = new DateTime(); 

if($date < $now) 
{ 
    // Do your stuff. 
} 

不过,既然你正在处理一个特定的日期,它肯定会永远成为过去?

+0

好点(关于具体日期) – ThisGuyHasTwoThumbs

0

可以使用date来实现这一目标:

<?php 
    $date = date('Y-m-d', strtotime('Friday 19th May 2017')); 
    $today = date('Y-m-d'); 

    if ($date < $today) { 
     //do some code 
    } 

这是什么一样,是通过使用strtotime它创建基于STR值的日期/时间分配$date今天等于。

$today被分配为date()这将返回服务器的当前时间戳,而不是用户计算机的本地时间。然后比较日期。

+0

为什么在'strtotime('2017年5月19日星期五') BenM

+0

@BenM我想这是更优雅的方式:) – ThisGuyHasTwoThumbs