回答編集履歴

5

テキスト修正

2019/07/28 00:59

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -196,7 +196,7 @@
196
196
 
197
197
 
198
198
 
199
- 二つの日付、あるいは日時の差分を取得する [moment#diff](https://momentjs.com/docs/#/displaying/difference/) を使うと、以下の2行
199
+ momentに用意されている、二つの日付、あるいは日時の差分を取得するメソッド [moment#diff](https://momentjs.com/docs/#/displaying/difference/) を使うと、以下の2行
200
200
 
201
201
 
202
202
 

4

テキスト修正

2019/07/28 00:58

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -106,11 +106,11 @@
106
106
 
107
107
 
108
108
 
109
- - moment [add](https://momentjs.com/docs/#/manipulating/add/)
109
+ - 日付または日時に指定の日数などを加える: [moment#add](https://momentjs.com/docs/#/manipulating/add/)
110
-
111
-
112
-
110
+
111
+     
112
+
113
- - moment [format](https://momentjs.com/docs/#/displaying/format/)
113
+ - 指定したフォーマットの文字列を取得: [moment#format](https://momentjs.com/docs/#/displaying/format/)
114
114
 
115
115
 
116
116
 
@@ -196,7 +196,7 @@
196
196
 
197
197
 
198
198
 
199
- 二つの日付、あるいは日時の差分を取得する、 moment の [diff](https://momentjs.com/docs/#/displaying/difference/) を使うと、以下の2行
199
+ 二つの日付、あるいは日時の差分を取得する、 [moment#diff](https://momentjs.com/docs/#/displaying/difference/) を使うと、以下の2行
200
200
 
201
201
 
202
202
 

3

テキスト修正

2019/07/28 00:21

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -189,3 +189,33 @@
189
189
 
190
190
 
191
191
  以上、参考になれば幸いです。
192
+
193
+
194
+
195
+ ### 追記
196
+
197
+
198
+
199
+ 二つの日付、あるいは日時の差分を取得する、 moment の [diff](https://momentjs.com/docs/#/displaying/difference/) を使うと、以下の2行
200
+
201
+
202
+
203
+ ```
204
+
205
+ var days = (end - start) / 1000 / 60 / 60 / 24;
206
+
207
+ days++;
208
+
209
+ ```
210
+
211
+
212
+
213
+ を、以下のように書くことができます。
214
+
215
+
216
+
217
+ ```
218
+
219
+ var days = moment(end).diff(moment(start), 'days');
220
+
221
+ ```

2

テキスト修正

2019/07/28 00:06

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- この回答では、ご質問のコードにある、 `<div class="output">` の中に、 開始日から終了日までの日付の文字列を、番号付きリスト `<ol>` で列挙するコードを示します。その際に、日付や日時を扱うときに、[Date](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Date)オブジェクトのままでやろうとするよりも、[moment](https://momentjs.com/)を使うと、分かり易いコードを書けることが多いので、これを使います。
5
+ この回答では、ご質問のコードにある、 `<div class="output">` の中に、 開始日から終了日までの日付の文字列を、番号付きリスト `<ol>` で列挙するコードを示します。また、日付や日時を扱うときに、[Date](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Date)オブジェクトのままでやろうとするよりも、[moment](https://momentjs.com/)を使うと、分かり易いコードを楽に書けることが多いので、これを使います。
6
6
 
7
7
 
8
8
 

1

テキスト修正

2019/07/27 22:55

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -102,6 +102,18 @@
102
102
 
103
103
 
104
104
 
105
+ 上記のコードで使っている moment のメソッドは以下の2点です。
106
+
107
+
108
+
109
+ - moment [add](https://momentjs.com/docs/#/manipulating/add/)
110
+
111
+
112
+
113
+ - moment [format](https://momentjs.com/docs/#/displaying/format/)
114
+
115
+
116
+
105
117
  #### (4) 日付のリストを作成する関数
106
118
 
107
119