Create Day, Hour, Minute and Second countdown in PHP

前端 未结 3 1650
無奈伤痛
無奈伤痛 2021-01-26 03:47

So far I\'ve got this script that counts down the days and hours, but how can I make it also do minutes and seconds?

$remaining = strtotime($ActiveListing[\'Lis         


        
相关标签:
3条回答
  • 2021-01-26 04:25

    I thought of a solution with date():

    $remaining = strtotime($ActiveListing['ListingExpires']) - time();
    list($months, $days, $hours, $minutes, $seconds) = explode(" ",date("n j H i s",$remaining));
    $months--;$days--;
    echo "$months months - $days days - $hours hours - $minutes minutes - $seconds seconds left";
    
    0 讨论(0)
  • 2021-01-26 04:32
    $remaining         = strtotime($ActiveListing['ListingExpires']) - time();
    $days_remaining    = floor($remaining/60/60/24);
    $hours_remaining   = floor(($remaining-($days_remaining*60*60*24))/60/60);
    $minutes_remaining = floor(($remaining-($days_remaining*60*60*24)-($hours_remaining*60*60))/60);
    $seconds_remaining = floor(($remaining-($days_remaining*60*60*24)-($hours_remaining*60*60))-($minutes_remaining*60));
    
    0 讨论(0)
  • 2021-01-26 04:46
    $edate = '2027-07-06 07:01:53';
    $datestr = $edate;//Your date
    $date=strtotime($datestr);//Converted to a PHP date (a second count)
    //Calculate difference
    $diff=$date-time();//time returns current time in seconds
    $days=floor($diff/(60*60*24));//seconds/minute*minutes/hour*hours/day)
    $hours=round(($diff-$days*60*60*24)/(60*60)); 
    
    0 讨论(0)
提交回复
热议问题