-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyobi.php
64 lines (52 loc) · 1.08 KB
/
yobi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
function get_day($year, $month){
$month_days = array(31,28,31,30,31,30,31,31,30,31,30,31);
if($month == 2){
if($year%4 == 0){
if($year%100 == 0 && $year%400 != 0){
$days = 28;
}
else{
$days =29;
}
}
else{
$days = 28;
}
}
else{
$days = $month_days[$month - 1];
}
return $days;
}
function get_week($year,$month,$day){
$yearindex = $year - 1;
$days = 0;
$weeks = array("月","火","水","木","金","土","日");
while ($yearindex > 0){
if (get_day($yearindex,2) == 29){
$days += 366;
}
else{
$days += 365;
}
$yearindex -= 1;
}
$monthindex = $month - 1;
while ($monthindex > 0){
$month_days = get_day($year, $monthindex);
$days += $month_days;
$monthindex -= 1;
}
$days += $day;
return $weeks[($days-1)%7];
}
echo "年を入力して下さい : ";
$year =trim(fgets(STDIN));
echo "月を入力して下さい : ";
$month =trim(fgets(STDIN));
echo "日を入力して下さい";
$day = trim(fgets(STDIN));
$week = get_week($year,$month,$day);
echo "{$year}年{$month}月{$day}日は{$week}曜日です\n";
?>