假设给定一个Timestamp timestamp
:如何建立月份的第一个和最后一个作为时间戳,给定的时间戳?
我使用约达时间来构建该月的第一天:
DateTime dateTime = new DateTime(timestamp);
MutableDateTime firstOfMonth = dateTime.toMutableDateTime();
firstOfMonth.setDayOfMonth(1);
firstOfMonth.setTime(0, 0, 0, 0);
,并在每月的最后一天:
MutableDateTime lastOfMonth = firstOfMonth.toMutableDateTime();
lastOfMonth.addMonths(1);
lastOfMonth.addMillis(-1);
但我想知道计算firstOfMonth
和lastOfMonth
这需要这么多的代码。有更清洁的方法吗?
这是相当不错的覆盖(尽管不正是这个问题)[这里] [1]。 [1]:http://stackoverflow.com/questions/7130948/joda-time-most-recent-week-and-month –