dongqu7778
2014-02-02 04:54
浏览 417
已采纳

为时间戳添加天,小时和分钟 - 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?

图片转代码服务由CSDN问答提供 功能建议

我无法通过 strtotime()添加天,小时和分钟。< / p>

代码:

  $ uncleanTotal = strtotime($ created_time); 
 $ uncleanTotal = strtotime(“+”。$ timeForUnclean [0  ]。“days”。$ timeForUnclean [1]。“hours”。$ timeForUnclean [2]。“minutes”); 
   
 
 

更确切地说,我是 试图从之前获得时间并添加天,小时和分钟,以查看它创建的时间是否大于当前时间(现在)或小于。 我使用 if 语句来检查这个。

代码:

  if($ cautionTotal&lt  ; = $ now)
 {
 echo“工作谨慎”; 
返回“黄色”; 
 
} 
如果($ uncleanTotal&lt; = $ now)
 {
 echo“working unclean”  ; 
返回“red”; 
} 
else if($ cautionTotal&gt; $ now&amp;&amp; $ uncleanTotal&gt; $ now)
 {
 echo“working clean”; 
返回“green”;  \ N} 
   
 
 

连连呢? 想法?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongxing1960 2014-02-02 05: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));
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题