回答編集履歴
4
コードの修正
test
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
-
print((now - pre).seconds)
|
21
|
+
print((now - pre).total_seconds())
|
22
22
|
|
23
23
|
print(now.timestamp() - pre.timestamp())
|
24
24
|
|
@@ -26,12 +26,12 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
-
**実行結果** [Wandbox](https://wandbox.org/permlink/
|
29
|
+
**実行結果** [Wandbox](https://wandbox.org/permlink/sUqdoievipWYhCzd)
|
30
30
|
|
31
31
|
```
|
32
32
|
|
33
|
-
7047
|
33
|
+
7980.425271
|
34
34
|
|
35
|
-
704
|
35
|
+
7980.425271034241
|
36
36
|
|
37
37
|
```
|
3
誤字修正
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
UNIX時間を利用しても同様の方法で解決できますが、やや直
|
7
|
+
UNIX時間を利用しても同様の方法で解決できますが、やや直感的でない印象を受けます。
|
8
8
|
|
9
9
|
```Python
|
10
10
|
|
2
追記
test
CHANGED
@@ -4,4 +4,34 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
UNIX時間を利用しても同様の方法で解決できますが、やや
|
7
|
+
UNIX時間を利用しても同様の方法で解決できますが、やや直観的でない印象を受けます。
|
8
|
+
|
9
|
+
```Python
|
10
|
+
|
11
|
+
import datetime
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
pre = datetime.datetime(2019, 4, 22, 12)
|
16
|
+
|
17
|
+
now = datetime.datetime.now()
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
print((now - pre).seconds)
|
22
|
+
|
23
|
+
print(now.timestamp() - pre.timestamp())
|
24
|
+
|
25
|
+
```
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
**実行結果** [Wandbox](https://wandbox.org/permlink/Lmo2DKhZLpW0klTi)
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
7047
|
34
|
+
|
35
|
+
7047.20519900322
|
36
|
+
|
37
|
+
```
|
1
追記
test
CHANGED
@@ -1,3 +1,7 @@
|
|
1
1
|
datetimeオブジェクト間の減算で、[timedeltaオブジェクト](https://docs.python.org/ja/3/library/datetime.html#timedelta-objects)が得られます。
|
2
2
|
|
3
3
|
差分の秒数が 20*60以下かどうか判定すれば良いでしょう。
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
UNIX時間を利用しても同様の方法で解決できますが、やや遠回りな印象を受けます。
|