php - Time remaining until specific time from current time of page load

后端 未结 3 1905
梦毁少年i
梦毁少年i 2020-12-03 04:08

I have to admit that having not even tried to code this myself this question may be a annoying to some but I\'m very surprised that I wasn\'t able to find a good example on

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 04:28

    I think it will usefull

    $startdate="2008-06-22 20:38:25"; 
    $enddate="2008-06-29 21:38:49"; 
    
    $diff=strtotime($enddate)-strtotime($startdate); 
    echo "diff in seconds: $diff
    \n
    \n"; // immediately convert to days $temp=$diff/86400; // 60 sec/min*60 min/hr*24 hr/day=86400 sec/day // days $days=floor($temp); echo "days: $days
    \n"; $temp=24*($temp-$days); // hours $hours=floor($temp); echo "hours: $hours
    \n"; $temp=60*($temp-$hours); // minutes $minutes=floor($temp); echo "minutes: $minutes
    \n"; $temp=60*($temp-$minutes); // seconds $seconds=floor($temp); echo "seconds: $seconds
    \n
    \n"; echo "Result: {$days}d {$hours}h {$minutes}m {$seconds}s
    \n"; echo "Expected: 7d 0h 0m 0s
    \n"; echo "time isss".time(); echo $date = date('Y-m-d H:i:s')"; ?>

提交回复
热议问题