回答編集履歴
2
t2
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
```PHP
|
2
2
|
|
3
3
|
<?php
|
4
4
|
|
@@ -10,19 +10,19 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
|
13
|
+
//時分秒の差を返す関数
|
14
14
|
|
15
15
|
function time_diff($d1, $d2){
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
-
|
19
|
+
//初期化
|
20
20
|
|
21
21
|
$diffTime = array();
|
22
22
|
|
23
23
|
|
24
24
|
|
25
|
-
|
25
|
+
//タイムスタンプ
|
26
26
|
|
27
27
|
$timeStamp1 = strtotime($d1);
|
28
28
|
|
@@ -30,19 +30,19 @@
|
|
30
30
|
|
31
31
|
|
32
32
|
|
33
|
-
|
33
|
+
//タイムスタンプの差を計算
|
34
34
|
|
35
35
|
$difSeconds = $timeStamp2 - $timeStamp1;
|
36
36
|
|
37
37
|
|
38
38
|
|
39
|
-
|
39
|
+
//秒の差を取得
|
40
40
|
|
41
41
|
$diffTime['seconds'] = $difSeconds % 60;
|
42
42
|
|
43
43
|
|
44
44
|
|
45
|
-
|
45
|
+
//分の差を取得
|
46
46
|
|
47
47
|
$difMinutes = ($difSeconds - ($difSeconds % 60)) / 60;
|
48
48
|
|
@@ -50,7 +50,7 @@
|
|
50
50
|
|
51
51
|
|
52
52
|
|
53
|
-
|
53
|
+
//時の差を取得
|
54
54
|
|
55
55
|
$difHours = ($difMinutes - ($difMinutes % 60)) / 60;
|
56
56
|
|
@@ -58,7 +58,7 @@
|
|
58
58
|
|
59
59
|
|
60
60
|
|
61
|
-
|
61
|
+
//結果を返す
|
62
62
|
|
63
63
|
return $diffTime;
|
64
64
|
|
@@ -70,13 +70,13 @@
|
|
70
70
|
|
71
71
|
|
72
72
|
|
73
|
-
|
73
|
+
//関数実行
|
74
74
|
|
75
75
|
$diffTimeOutPut = time_diff($dateTime1, $dateTime2);
|
76
76
|
|
77
77
|
|
78
78
|
|
79
|
-
|
79
|
+
//日時の差を表示
|
80
80
|
|
81
81
|
echo $diffTimeOutPut['hours'].'時間<br/>';
|
82
82
|
|
1
t1
test
CHANGED
@@ -90,7 +90,7 @@
|
|
90
90
|
|
91
91
|
|
92
92
|
|
93
|
-
引用元
|
93
|
+
[引用元](https://wepicks.net/phpsample-date-2daytimedif/)
|
94
94
|
|
95
95
|
|
96
96
|
|