dongqu7778 2014-02-01 20:54
浏览 498
已采纳

为时间戳添加天,小时和分钟 - PHP

I am having difficulty adding days, hours, and minutes through strtotime().

Code:

$uncleanTotal = strtotime($created_time);
$uncleanTotal = strtotime("+".$timeForUnclean[0] . " days ". $timeForUnclean[1] ." hours ". $timeForUnclean[2] ." minutes");

To be more exact I am trying to get a time from before and add days, hours, and minutes to see if that time it creates is greater than the current time (now) or lesser than. I am than using an if statement to check this.

Code:

if($cautionTotal <= $now)
{
    echo "working caution";
    return "yellow";

}
else if( $uncleanTotal <= $now)
{
    echo  "working unclean";
    return "red";
}
else if($cautionTotal > $now && $uncleanTotal > $now)
{
    echo  "working clean";
    return "green";
}

Suggestions? Thoughts?

  • 写回答

1条回答 默认 最新

  • dongxing1960 2014-02-01 21:08
    关注

    You're missing the source date in the statement where you're doing the addition:

    Try:

    $uncleanTotal = strtotime($created_time . "+".$timeForUnclean[0] . " days ". $timeForUnclean[1] ." hours ". $timeForUnclean[2] ." minutes");
    

    Alternatively you can pass strtotime($created_time) as the second parameter to strtotime to get the same result as above:

    $uncleanTotal = strtotime("+".$timeForUnclean[0] . " days ". $timeForUnclean[1] ." hours ". $timeForUnclean[2] ." minutes", strtotime($created_time));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?