2014-10-01 58 views
-1

我有这样的代码,我需要一个良好的状态,以阻止人们预订了一天回报的警报日期相同datepickup

$output['date_pickup'] = $pickup; 
$output['date_return'] = $return; 

// strtotime 
$pickup_dtime = strtotime($output['date_pickup'] . $output['time_pickup']); 
$return_dtime = strtotime($output['date_return'] . $output['time_return']); 

// PAST TIME? 
if (date('Y-m-d') == $output['date_pickup'] && date_i18n('H:i') > $output['time_pickup']) 
    $error .= sprintf(__('Today, you cannot book before %s.', 'textZ'), date_i18n('H:i')) . '<br />'; 

我尝试这种代码,但我不能保留任何方式的日期retrn的比24H大

if ($return < 86400) 
    $error .= __('today you cannot book.', 'textZ') . '<br />'; 

所以你能帮助,请

+0

您能否澄清一下您的问题,确实不清楚 – 2014-10-25 01:52:54

回答

-1

下面拨弄显示了如何使用由JavaScript Date对象提供的TIMESTRING容易做到这一点:
http://jsfiddle.net/jlss/au4tLncg/

基本上是:

var now = new Date(pickup).getTime(); 
var target = new Date(return).getTime(); 

if (now+(24*60*60*1000) <= target) { 
    return true; 
} 
return false; 

注意,在新的浏览器(不IE8-),你也可以使用。现在()代替.getTime() (来源:How do you get a timestamp in JavaScript?

注:看起来你的代码示例是PHP虽然,而不是JavaScript/jquery

在PHP中,您可以使用strtotime()而不是Date对象,参考:http://be2.php.net/function.strtotime 一般示例:

if (($timestamp = strtotime($str)) === false) { 
    echo "The string ($str) is bogus"; 
} else { 
    echo "$str == " . date('l dS \o\f F Y h:i:s A', $timestamp); 
}