我正在使用YearMonth对象joda.time,并希望在此对象中获取月份日期的最后一天.
yearMonth.monthOfYear().getMaximumValue(); //return 12 as the maximum month value is =12
Run Code Online (Sandbox Code Playgroud)
但我想要的是特定月份的最大日期?例如30或31.我怎么才能得到它?
DateTime具有此现成功能.
DateTime dt = new DateTime();
System.out.println(dt.dayOfMonth().getMaximumValue());
Run Code Online (Sandbox Code Playgroud)
但是如果你想要它用于YearMonth,那么将YearMonth转换为DateTime并按上述方式执行:
YearMonth ym = new YearMonth();
dt = ym.toDateTime(null);
System.out.println(dt.dayOfMonth().getMaximumValue());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6070 次 |
| 最近记录: |