java获取指定年月的开始时间与结束时间
16lz
2021-05-09
public static Date getBeginTime(int year, int month) {
YearMonth yearMonth = YearMonth.of(year, month);
LocalDate localDate = yearMonth.atDay(1);
LocalDateTime startOfDay = localDate.atStartOfDay();
ZonedDateTime zonedDateTime = startOfDay.atZone(ZoneId.of("Asia/Shanghai"));
return Date.from(zonedDateTime.toInstant());
}
public static Date getEndTime(int year, int month) {
YearMonth yearMonth = YearMonth.of(year, month);
LocalDate endOfMonth = yearMonth.atEndOfMonth();
LocalDateTime localDateTime = endOfMonth.atTime(23, 59, 59, 999);
ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.of("Asia/Shanghai"));
return Date.from(zonedDateTime.toInstant());
}
©著作权归作者所有:来自51CTO博客作者caoqishun的原创作品,如需转载,请注明出处,否则将追究法律责任
YearMonth yearMonth = YearMonth.of(year, month);
LocalDate localDate = yearMonth.atDay(1);
LocalDateTime startOfDay = localDate.atStartOfDay();
ZonedDateTime zonedDateTime = startOfDay.atZone(ZoneId.of("Asia/Shanghai"));
return Date.from(zonedDateTime.toInstant());
}
public static Date getEndTime(int year, int month) {
YearMonth yearMonth = YearMonth.of(year, month);
LocalDate endOfMonth = yearMonth.atEndOfMonth();
LocalDateTime localDateTime = endOfMonth.atTime(23, 59, 59, 999);
ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.of("Asia/Shanghai"));
return Date.from(zonedDateTime.toInstant());
}
©著作权归作者所有:来自51CTO博客作者caoqishun的原创作品,如需转载,请注明出处,否则将追究法律责任
每一份赞赏源于懂得
赞赏
0人进行了赞赏支持
更多相关文章
- 获取当天最大或最小日期
- Pycharm 查看代码引用时,想跳回到上一步 设置
- MP4:文件类型mp42转码方案
- jenkins相关
- Nginx 1.18.0配置SSL问题
- Django 使用正则匹配URL 并将匹配成功的值传递给视图函数
- Table 'mysql.user' doesn't exist解决方案
- lnmp一键安装包搭建lnmp环境,二种方式
- 收藏分享:众多PPT模板,分享给需要的你!