我怎样才能正确地写这个? 我想检查从publish_start日到publish_end日已经过去了多少天,当它们超过30天时,就会显示一条消息。
var a = new Date("<?php echo $this->item->publish_start; ?>");
var b = a.getDate();
var c = new Date("<?php echo $this->item->publish_end; ?>");
var d = c.getDate();
var e = d - b ;
if( e > 30) {
alert("<?php echo JText::_('You cant put more than 30 days'); ?>");
return false;
}
最佳答案
编辑:澄清后更新
您最好在 PHP 中找出日期之间的差异,然后将该值传递给 JavaScript。
我不知道这两个变量的日期格式是什么,但如果它们是unix时间戳,你可以这样做:
var e = <?php echo floor(strtotime($this->item->publish_end)-strtotime($this->item->publish_start))/86400); ?>
if( e > 30) {
alert("<?php echo JText::_('You cant put more than 30 days'); ?>");
return false;
}
关于php - 查看已经过去了多少天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11182341/