Last active
August 29, 2015 14:04
-
-
Save tomoTaka01/ca0a91f9059bf5d9a8ad to your computer and use it in GitHub Desktop.
1時間毎の時間を取得するサンプル(Java6,Java8) Getting every one hour using Java6 and Java8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void test1() { | |
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss"); | |
Calendar calendar = Calendar.getInstance(); | |
calendar.set(Calendar.HOUR, 0); | |
calendar.set(Calendar.MINUTE, 0); | |
calendar.set(Calendar.SECOND, 0); | |
calendar.set(Calendar.MILLISECOND, 0); | |
for (int i = 0; i < 48; i++) { | |
calendar.add(Calendar.HOUR, 1); | |
System.out.println(format.format(calendar.getTime())); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void test2() { | |
LocalDateTime now = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0); | |
System.out.println(now.format(DateTimeFormatter.ISO_DATE_TIME)); | |
IntStream.range(0, 48).mapToObj(i -> now.plusHours(i)).forEach(p -> { | |
System.out.println(p.format(DateTimeFormatter.ISO_DATE_TIME)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment