LoginSignup
0
0

More than 1 year has passed since last update.

【PHP】閏年判定プログラム

Last updated at Posted at 2022-05-06

コード

1・4で割り切れる年は閏年
2・400で割る切れる年はうるう年
3・100で割り切れる年は閏年ではない(※400で割る切れる年は除く)

↓上級者向け

<?php
$uru_year =  DateTimeImmutable::createFromFormat('Y', 1900)->format('L');
echo $uru_year ? '閏年です。':'平年です。'; 

image.pngimage.png

↓初級者向け

<?php
$uru = '閏年です。';
$normal = '平年です。';
$year = 1600;

if($year % 400 === 0){
     echo $uru;
}else{
    echo ($year % 4 === 0 && $year % 100 != 0) ? $uru:$normal;
}
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0