使用threeten,LocalDate获取每月的第一天和最后一天 [英] Get first and last day of month using threeten, LocalDate

查看:785
本文介绍了使用threeten,LocalDate获取每月的第一天和最后一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个LocalDate需要获取该月的第一天和最后一天。
我该怎么做?

I have a LocalDate which needs to get the first and last day of the month. How do I do that?

例如。 13/2/2014
我需要以LocalDate格式获得1/2/2014和28/2/2014。

eg. 13/2/2014 I need to get 1/2/2014 and 28/2/2014 in LocalDate formats.

使用threeten LocalDate类。

Using threeten LocalDate class.

推荐答案

只需使用 withDayOfMonth lengthOfMonth()

LocalDate initial = LocalDate.of(2014, 2, 13);
LocalDate start = initial.withDayOfMonth(1);
LocalDate end = initial.withDayOfMonth(initial.lengthOfMonth());

这篇关于使用threeten,LocalDate获取每月的第一天和最后一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆