php倒计时 时分秒 (每个月1号到最后一天)

$startDate = date('Y-m-01', strtotime(date("Y-m-d")));
        $endDate = date('Y-m-d', strtotime("$startDate +1 month -1 day"));
        // 将日期转换为Unix时间戳
        $endDate=$endDate." 23:59:59";
        $startDateStr = strtotime($startDate);
        $endtDateStr = strtotime($endDate);
        $total = $endtDateStr-$startDateStr;

        $now = strtotime(date('Y-m-d H:i:s'));
        $remain = $endtDateStr-$now;
        $day= intval($remain/86400);;//天
        $remains = $remain%86400;
        $hour = intval($remains/3600);
        //计算分钟数
        $remain1 = $remain%3600;
        $minute = intval($remain1/60);
        //计算秒数
        $second = $remain%60;
        echo $day."天".$hour.'小时'.$minute.'分'.$second."秒";

猜你喜欢

转载自blog.csdn.net/adminyan/article/details/79257291