Skip to content

Instantly share code, notes, and snippets.

@suin
Created February 3, 2012 13:41
Show Gist options
  • Save suin/1730217 to your computer and use it in GitHub Desktop.
Save suin/1730217 to your computer and use it in GitHub Desktop.
閏年かどうかを判定する ref: http://qiita.com/items/2012
<?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