如何创建条件语句,如if date("Y-m-d h:i:s");在date("Y-m-d h:i:s");之后超过30秒。
我以前用过date("Y-m-d h:i:s");< date("Y-m-d h:i:s");+ 30,但是这似乎不起作用。
帮助?
发布于 2010-06-20 20:36:41
使用strtotime()将它们转换为UNIX time。
例如:
if(strtotime($date2) - strtotime($date1) > 30) {
// $date2 is more than 30 seconds after $date1
}或
if(abs(strtotime($date2) - strtotime($date1)) > 30) {
// $dates are more than 30 second apart
}发布于 2010-06-20 20:38:14
使用strtotime()将两个日期转换为unix时间戳,然后将所需的秒数与秒相加,并进行整数比较。
发布于 2010-06-20 20:36:55
改为使用unixtime。只需将日期(“Y-m-d h:i:s”)转换为日期(“U”)或仅转换为时间()。strototime()可以帮助你解决这个问题。它以秒为单位显示自Unix纪元(1970年1月1日00:00:00 GMT)以来的时间。那么这个方法$unixtime + 30也会工作得很好;)
https://stackoverflow.com/questions/3079229
复制相似问题