質問編集履歴

5

プログラム修正

2019/04/21 11:24

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -30,9 +30,9 @@
30
30
 
31
31
 
32
32
 
33
- SimpleDateFormat firstOfHourFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:00");
33
+ SimpleDateFormat firstOfHourFormat = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
34
34
 
35
- SimpleDateFormat lastOfHourFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:59");
35
+ SimpleDateFormat lastOfHourFormat = new SimpleDateFormat("yyyy-MM-dd HH:59:59");
36
36
 
37
37
  String firstOfHourDateStr = firstOfHourFormat.format(currentDate);
38
38
 

4

問題修正

2019/04/21 11:24

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -6,11 +6,11 @@
6
6
 
7
7
 
8
8
 
9
- `2019-04-21 16:00:00`
9
+ Date型 `2019-04-21 16:00:00`
10
10
 
11
- `2019-04-21 16:59:00`
11
+ Date型 `2019-04-21 16:59:00`
12
12
 
13
- とこの2つを取得したいです。
13
+ とこの2つを取得したいです(上記便宜上、文字列で書いていますが、Date型で取得したいです)。
14
14
 
15
15
 
16
16
 

3

プログラム修正

2019/04/21 08:44

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -30,9 +30,9 @@
30
30
 
31
31
 
32
32
 
33
- SimpleDateFormat firstOfHourFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:00");
33
+ SimpleDateFormat firstOfHourFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:00");
34
34
 
35
- SimpleDateFormat lastOfHourFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:59");
35
+ SimpleDateFormat lastOfHourFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:59");
36
36
 
37
37
  String firstOfHourDateStr = firstOfHourFormat.format(currentDate);
38
38
 

2

コードの修正

2019/04/21 08:24

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -50,8 +50,8 @@
50
50
 
51
51
 
52
52
 
53
- System.out.println(firstOfHourDateStr);
53
+ System.out.println(firstOfHourDate);
54
54
 
55
- System.out.println(lastOfHourDateStr);
55
+ System.out.println(lastOfHourDate);
56
56
 
57
57
  ```

1

サンプルコード追加

2019/04/21 08:20

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -15,3 +15,43 @@
15
15
 
16
16
 
17
17
  どういう方法があるでしょうか?
18
+
19
+
20
+
21
+ ぱっと思いつくのは以下ぐらいです。
22
+
23
+ ですが、無理やり生成している感じがして、もっと良い方法はないのかな?と思っています。
24
+
25
+
26
+
27
+ ```Java
28
+
29
+ Date currentDate = new Date();
30
+
31
+
32
+
33
+ SimpleDateFormat firstOfHourFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:00");
34
+
35
+ SimpleDateFormat lastOfHourFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:59");
36
+
37
+ String firstOfHourDateStr = firstOfHourFormat.format(currentDate);
38
+
39
+ String lastOfHourDateStr = lastOfHourFormat.format(currentDate);
40
+
41
+
42
+
43
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
44
+
45
+
46
+
47
+ Date firstOfHourDate = sdf.parse(firstOfHourDateStr);
48
+
49
+ Date lastOfHourDate = sdf.parse(lastOfHourDateStr);
50
+
51
+
52
+
53
+ System.out.println(firstOfHourDateStr);
54
+
55
+ System.out.println(lastOfHourDateStr);
56
+
57
+ ```