回答編集履歴

5

テキスト修正

2020/07/10 06:47

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -44,7 +44,7 @@
44
44
 
45
45
  Durations
46
46
 
47
- [https://momentjs.com/docs/#/durations/](https://momentjs.com/docs/#/durations)
47
+ [https://momentjs.com/docs/#/durations/](https://momentjs.com/docs/#/durations/)
48
48
 
49
49
 
50
50
 

4

テキスト修正

2020/07/10 06:47

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -44,11 +44,11 @@
44
44
 
45
45
  Durations
46
46
 
47
- https://momentjs.com/docs/#/durations/
47
+ [https://momentjs.com/docs/#/durations/](https://momentjs.com/docs/#/durations)
48
48
 
49
49
 
50
50
 
51
- を使ったほうがよいです。以下はこれを使ったサンプルです。
51
+ を使ったほうがよいかもしれません。以下はこれを使ったサンプルです。
52
52
 
53
53
 
54
54
 

3

テキスト修正

2020/07/10 04:48

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -52,7 +52,11 @@
52
52
 
53
53
 
54
54
 
55
+
56
+
55
- https://codepen.io/jun68ykt/pen/QWyxwOg?editors=0012
57
+ - **動作確認用codepen:** [https://codepen.io/jun68ykt/pen/QWyxwOg?editors=0012](https://codepen.io/jun68ykt/pen/QWyxwOg?editors=0012)
58
+
59
+
56
60
 
57
61
 
58
62
 

2

テキスト修正

2020/07/10 04:47

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -19,3 +19,41 @@
19
19
  ```
20
20
 
21
21
  - **動作確認用codepen:** [https://codepen.io/jun68ykt/pen/ExPLQbV?editors=0012](https://codepen.io/jun68ykt/pen/ExPLQbV?editors=0012)
22
+
23
+
24
+
25
+ ### 追記
26
+
27
+
28
+
29
+ 上記のコードでやっていることは、
30
+
31
+
32
+
33
+ - 今日の日付の1時0分0秒という日時を持ったmomentオブジェクトを作り、`timeRequired` に入れる。
34
+
35
+ - 今日の日付の0時1分2秒という日時を持ったmomentオブジェクトを作り、`timeElapsed` に入れる。
36
+
37
+ - 上記の2つの日時の差分を秒換算で、`timeRemaining` に得る。
38
+
39
+
40
+
41
+ というものです。ですので、`timeRequired` や `timeElapsed` は日時を表すものであって、1時間や1分2秒だったりの時間幅を表しているわけではないです。この点がちょっとすっきりしないということであれば、時間幅を表すオブジェクトとして、より適切な
42
+
43
+
44
+
45
+ Durations
46
+
47
+ https://momentjs.com/docs/#/durations/
48
+
49
+
50
+
51
+ を使ったほうがよいです。以下はこれを使ったサンプルです。
52
+
53
+
54
+
55
+ https://codepen.io/jun68ykt/pen/QWyxwOg?editors=0012
56
+
57
+
58
+
59
+ ただしこの場合は、文字列の`'01:00:00'`や `'00h01m02s'` から、`moment.duration()` に渡すパラメータを作るところを自分で書く必要があります。

1

テキスト修正

2020/07/10 04:45

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -4,13 +4,13 @@
4
4
 
5
5
  ```javascript
6
6
 
7
- const imeRequired = moment('01:00:00', 'HH:mm:ss');
7
+ const timeRequired = moment('01:00:00', 'HH:mm:ss');
8
8
 
9
9
  const timeElapsed = moment('00h01m02s', 'HHhmmmsss');
10
10
 
11
11
 
12
12
 
13
- const timeRemaining = imeRequired.diff(timeElapsed, 'seconds');
13
+ const timeRemaining = timeRequired.diff(timeElapsed, 'seconds');
14
14
 
15
15
 
16
16