年月日合法判断:
HTML代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>年月日合法判断</title>
</head>
<body>
<form action="check.php" method="post">
<input type="text" name="year">年
<input type="text" name="month">月
<input type="text" name="day">日
<br>
<button>计算</button>
</form>
</body>
</html>
php代码:
<?php
$year = $_POST['year'];
$month = $_POST['month'];
$day = $_POST['day'];
if ($month<=12 && $month>=1) {
if ($month==1 || $month==3 ||$month==5 ||$month==7 ||$month==8 ||$month==10 ||$month==12) {
if ($day>=1 &&$day<=31) {
echo " 合法日期";
echo"<br>";
echo " $year 年";
echo " $month 月";
echo " $day 日";
}else{
echo "请输入合法日期";
}
}elseif ($month==4 || $month==6 ||$month==9 ||$month==11 ) {
if ($day>=1 &&$day<=30) {
echo " 合法日期";
echo"<br>";
echo " $year 年";
echo " $month 月";
echo " $day 日";
}else{
echo "请输入正确日期";
}
}elseif ($month==2) {
if ($year%4==0&&$year%100!=0) {
if ($day>=1 &&$day<=29) {
echo " 合法日期";
echo"<br>";
echo " $year 年";
echo " $month 月";
echo " $day 日";
}else{
echo "请输入正确日期";
}
}elseif($day>=1 &&$day<=28){
echo " 合法日期";
echo"<br>";
echo " $year 年";
echo " $month 月";
echo " $day 日";
}else{
echo "请输入合法日期";
}
}
}else{
echo "请输入正确月份";
}
echo "<br>";
$start="$year-01-01";
$end="$year-$month-$day";
$datetime_start = date_create($start);
$datetime_end = date_create($end);
$days = date_diff($datetime_start, $datetime_end)->days;
echo "$year 已经过了 $days";
?>
|