search
Homephp教程PHP源码收集了几款常用php日期操作

<script>ec(2);</script>

这里的日期操作函数有时间的增加,计算出给出的日期是星期几 ,检查日期是否合法日期  时间比较函数,返回两个日期相差几秒、几分钟、几小时或几天

function dateadd($date, $int, $unit = "d") {

//时间的增加(还可以改进成时分秒都可以增加,有时间再补上)
$datearr = explode("-", $date);
$value[$unit] = $int;

//

    return date("y-m-d", mktime(0,0,0, $datearr[1] + $value['m'], $datearr[2] + $value['d'], $datearr[0] + $value['y']));

//一聚教程网

}

function getweekday($date) {  //计算出给出的日期是星期几
$datearr = explode("-", $date);
    return date("w", mktime(0,0,0,$datearr[1],$datearr[2],$datearr[0]));

//

}
?>



function check_date($date) { //检查日期是否合法日期
$datearr = explode("-", $date);
    if (is_numeric($datearr[0]) && is_numeric($datearr[1]) && is_numeric($datearr[2])) { //一聚教程网
        return checkdate($datearr[1],$datearr[2],$datearr[0]);
    }
    return false;
}
function check_time($time) {  //检查时间是否合法时间

//一聚教程网

$timearr = explode(":", $time);
    if (is_numeric($timearr[0]) && is_numeric($timearr[1]) && is_numeric($timearr[2])) {

//

        if (($timearr[0] >= 0 && $timearr[0] = 0 && $timearr[1] = 0 && $timearr[2]

//php

            return true;
        else
            return false;
    }
    return false;
}


function datediff($date1, $date2, $unit = "") {

//时间比较函数,返回两个日期相差几秒、几分钟、几小时或几天
//
switch ($unit) {
        case 's':
$dividend = 1;
            break;
        case 'i':
$dividend = 60;

            break;
        case 'h':
$dividend = 3600;
            break;
        case 'd':
$dividend = 86400;
            break; //
        default:
$dividend = 86400;
    }
$time1 = strtotime($date1);
$time2 = strtotime($date2);
    if ($time1 && $time2) //
        return (float)($time1 - $time2) / $dividend;
    return false;
}
?>

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.