search
HomeBackend DevelopmentPHP ProblemPHP determines whether it is a leap year

PHP determines whether it is a leap year

Oct 29, 2019 pm 01:14 PM
phpleap year

PHP determines whether it is a leap year

1, PHP leap year calculation method 1:

The leap year is when the remainder of 4 is 0, the remainder of 100 is not equal to 0, and the remainder of 400 is equal to 0 The year is a leap year.

$day = date('Y');
if ($day%4==0&&($day%100!=0 || $day%400==0)){
    echo $day.'是闰年';
}else{
    echo $day.'不是闰年';
}

2, PHP method two to determine leap year:

date('L'); you can directly determine whether the current year is a leap year, return 1 if true, otherwise return 0.

$year = 2008;//可以像上例一样用mt_rand随机取一个年,也可以随便赋值。
$time = mktime(20,20,20,4,20,$year);//取得一个日期的 Unix 时间戳;
if (date("L",$time)==1){ //格式化时间,并且判断是不是闰年,后面的等于一也可以省略;
echo $year."是闰年";
}else{
echo $year."不是闰年";
}

3, PHP’s third method of judging leap years and calculating leap years:

$year = 2000;
$time = mktime(20,20,20,2,1,$year);//取得一个日期的 Unix 时间戳;
if (date("t",$time)==29){ //格式化时间,并且判断2月是否是29天;
echo $year."是闰年";//是29天就输出时闰年;
}else{
echo $year."不是闰年";
}

Recommendation: php server

The above is the detailed content of PHP determines whether it is a leap year. For more information, please follow other related articles on the PHP Chinese website!

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 Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool