高亮表日期中的错误

时间:2014-02-06 11:07:14

标签: javascript php css

这段代码有什么问题?我想强调从现在开始的所有日子+ 2周。但是它们都会以.highlight类突出显示。错误在哪里?

<?php 
// get two weeks from now
$date_in_two_weeks = strtotime('+2 weeks');
$date_in_two_weeks = date("Y-m-d",$date_in_two_weeks);

// get the date to compare, from db or whatever you want
$date_to_compare = "2014-02-01";

// compare the date in your list to now + 2 weeks and then put the date difference into $days_difference
$date_from_list = new DateTime($date_to_compare);
$date_in_two_weeks = new DateTime($date_in_two_weeks);
$days_difference = $date_from_list->diff($date_in_two_weeks);

if ($days_difference->days > 14) {
    $highlight_css_class = "highlight";
} else {
    $highlight_css_class = "none";
}
?>
<style>
.highlight { 
    color:#cc0000;
}
.none { 
}
</style>
<fieldset>
<table class="tablesorter" id="my-table" border="1" style="border-collapse:collapse">
        <thead>
            <tr>
                <th>REK</th>
                <th>BESCHRIJVING</th>
                <th>VERVALDATUM</th>
            </tr>
        </thead>
        <tbody>


<tr><td>A1</td><td>hamburger</td><td class="<?php echo $highlight_css_class;?>">2014-02-10</td></tr>

<tr><td>A1</td><td>tomato</td><td class="<?php echo $highlight_css_class;?>">2014-06-10</td></tr>


        </tbody>
    </table>

我测试了代码并改变了很多,但我无法让它工作.... 请提前获取任何帮助。

1 个答案:

答案 0 :(得分:0)

试试这个

$date_in_two_weeks = strtotime('+2 week');

而不是

$date_in_two_weeks = strtotime('+2 weeks');

为了获得接下来两周的正确时间戳,您必须week代替weeks