Skip to content

Instantly share code, notes, and snippets.

@ainvyu
Created December 29, 2015 04:37
Show Gist options
  • Save ainvyu/e9dbfbf56278748a4c5d to your computer and use it in GitHub Desktop.
Save ainvyu/e9dbfbf56278748a4c5d to your computer and use it in GitHub Desktop.
Date sample rev.3 (Java 8 ver.)
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* Created by vine on 15. 12. 29..
*/
public class Main {
public static void main(String args[]) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDate targetDate = LocalDate.parse("20160102", formatter)
.minusMonths(1)
.withDayOfMonth(1);
System.out.println(targetDate);
List<String> days = IntStream
.range(0, targetDate.lengthOfMonth())
.mapToObj(i -> targetDate.plusDays(i).format(formatter))
.collect(Collectors.toList());
System.out.println(days);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment