PHP-如何检查一年是否为二等分(即a年)? [英] PHP - How to check whether a year is bisect (i.e. a leap year)?

查看:124
本文介绍了PHP-如何检查一年是否为二等分(即a年)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查php中的年份是否是等分的(即a年)?

How can I check whether a year is bisect (i.e. a leap year) in php ?

推荐答案

您可以使用PHP的 date()函数为此...

You can use PHP's date() function to do this...

// L will return 1 or 0 for leap years
echo date('L');

// use your own timestamp
echo date('L', strtotime('last year'));

// for specific year
$year = 1999;
$leap = date('L', mktime(0, 0, 0, 1, 1, $year));
echo $year . ' ' . ($leap ? 'is' : 'is not') . ' a leap year.';

让我知道这是否对您有用吗,干杯!

Let me know if this does this trick for you, Cheers!

更新:添加了特定年份的示例

UPDATE: Added Example for Specific Year

这篇关于PHP-如何检查一年是否为二等分(即a年)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆