';$end=strtotime('2018-8-16 00:00:00');$d=$end-$now;$y=floor($d/3600/24/30/12);$m=($d/3600/24/30)%12;$dt=($d/3600/24)%30;echo "距世界杯还有{$y}年{$m}个月{$dt}天";
How can you write if you have an error in writing this month?
Does this error have an effect?
Reply content:
';$end=strtotime('2018-8-16 00:00:00');$d=$end-$now;$y=floor($d/3600/24/30/12);$m=($d/3600/24/30)%12;$dt=($d/3600/24)%30;echo "距世界杯还有{$y}年{$m}个月{$dt}天";
How can you write if you have an error in writing this month?
Does this error have an effect?
DateTime can be used to calculate a diff of two dates very quickly and easily.
diff($datetime2);list($y, $m, $d) = explode('-', $interval->format('%Y-%m-%d'));echo "距世界杯还有{$y}年{$m}个月{$d}天";
The key is the logic is unclear, February 1 to March 1 Whether it is one months or 28 (29) days?
There's a crooked way to get the worth. Date parsing, and 1970-1-1 comparison
https://3v4l.org/1QEbC
Why use time ()
Why not go to the wee hours of the day?
$y =floor ($ D/3600/24/30/12); This year is a bit far-fetched, some months more than 30 days.
If your machine time is not very bad, you should not have much error.
$dt = ($d/3600/24)%30; There's something wrong with that.
For a time, you can use the third-party library of Carbon
for quick calculations.