通过LocalDate获取某一年份的12个月的月初和月末

本文详细介绍了如何使用Java的LocalDate类来获取指定年份每个月的第一天和最后一天,这对于处理日期相关的计算和数据分析非常有用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    //获取指定年份的12个月的月初和月末
    LocalDate oneStart = LocalDate.parse(year+"-01-01", ISO_DATE);
    LocalDate oneEnd = oneStart.with(TemporalAdjusters.lastDayOfMonth());
    LocalDate twoStart = LocalDate.parse(year+"-02-01", ISO_DATE);
    LocalDate twoEnd = twoStart.with(TemporalAdjusters.lastDayOfMonth());
    LocalDate threeStart = LocalDate.parse(year+"-03-01", ISO_DATE);
    LocalDate threeEnd = threeStart.with(TemporalAdjusters.lastDayOfMonth());
    LocalDate fourStart = LocalDate.parse(year+"-04-01", ISO_DATE);
    LocalDate fourEnd = fourStart.with(TemporalAdjusters.lastDayOfMonth());
    LocalDate fiveStart = LocalDate.parse(year+"-05-01", ISO_DATE);
    LocalDate fiveEnd = fiveStart.with(TemporalAdjusters.lastDayOfMonth());
    LocalDate sixStart = LocalDate.parse(year+"-06-01", ISO_DATE);
    LocalDate sixEnd = sixStart.with(TemporalAdjusters.lastDayOfMonth());
    LocalDate sevenStart = LocalDate.parse(year+"-07-01", ISO_DATE);
    LocalDate sevenEnd = sevenStart.with(TemporalAdjusters.lastDayOfMonth());
    LocalDate eightStart = LocalDate.parse(year+"-08-01", ISO_DATE);
    LocalDate eightEnd = eightStart.with(TemporalAdjusters.lastDayOfMonth());
    LocalDate nineStart = LocalDate.parse(year+"-09-01", ISO_DATE);
    LocalDate nineEnd = nineStart.with(TemporalAdjusters.lastDayOfMonth());
    LocalDate tenStart = LocalDate.parse(year+"-10-01", ISO_DATE);
    LocalDate tenEnd = tenStart.with(TemporalAdjusters.lastDayOfMonth());
    LocalDate elevenStart = LocalDate.parse(year+"-11-01", ISO_DATE);
    LocalDate elevenEnd = elevenStart.with(TemporalAdjusters.lastDayOfMonth());
    LocalDate twelveStart = LocalDate.parse(year+"-12-01", ISO_DATE);
    LocalDate twelveEnd = twelveStart.with(TemporalAdjusters.lastDayOfMonth());
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值