Created
February 3, 2012 13:41
-
-
Save suin/1730217 to your computer and use it in GitHub Desktop.
閏年かどうかを判定する ref: http://qiita.com/items/2012
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// まじめに計算する方法 | |
function isLeapYear($year) | |
{ | |
return ( ( $year % 4 === 0 and $year % 100 !== 0 ) or $year % 400 === 0 ); | |
} | |
$years = range(2000, 2012); | |
foreach ( $years as $year ) { | |
echo $year, ' ', var_export(isLeapYear($year), true), PHP_EOL; | |
} | |
// 2月29日があるかを判定する方法 | |
function isLeapYear2($year) | |
{ | |
return checkdate(2, 29, $year); | |
} | |
$years = range(2000, 2012); | |
foreach ( $years as $year ) { | |
echo $year, ' ', var_export(isLeapYear2($year), true), PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment