指定 年 周 星期 获取这周的开始日期和结束日期

 //一年的开始周 java为1.
private static LocalDate parseWeekBegin(int year, int week) {

return LocalDate.parse(year + " " + week,
new DateTimeFormatterBuilder().appendPattern("YYYY w").parseDefaulting(WeekFields.ISO.dayOfWeek(), 1).toFormatter());
}

private static LocalDate parseWeekEnd(LocalDate begin) {
return begin.with(TemporalAdjusters.next(DayOfWeek.SUNDAY));
}

 

调用:

LocalDate begin = parseWeekBegin(2016,31);
System.out.println(begin);
System.out.println(parseWeekEnd(begin) );

 

java的日期和时间:http://www.importnew.com/14857.html

Java 8 Date Time API Example Tutorial – LocalDate, Instant, LocalDateTime, Parse and Format

http://www.tuicool.com/articles/a6vq63E

posted @ 2016-08-15 14:22  Bigben  阅读(1878)  评论(0编辑  收藏  举报