I am currently using jodaTime DateTime class for my Java project. But it does not have support for quarter of the year and week of the year.
Is there any Java library which can be used for that purpose?
I am currently using jodaTime DateTime class for my Java project. But it does not have support for quarter of the year and week of the year.
Is there any Java library which can be used for that purpose?
In java 8 DateTimeFormatter
supports quarters using q
format and week of the year using w
:
LocalDate date = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("qqq w");
String text = date.format(formatter);
Results in third quarter and 31st week of the year for todays date (July 25th):
"Q3 31"
Is there any Java library which can be used for that purpose?
Yes.
The ThreeTen-Extra project has classes for:
Quarter
Q1
, Q2
, Q3
, and Q4
. These are defined as January–March, April–June, July–September, and October–December.YearQuarter
2007-Q2
.YearWeek
2015-W13
.No need to reinvent the wheel with your own. These classes also provide extra functionality such as math with plus
and minus
methods.
ThreeTen-Extra extends the java.time framework built into Java 8 and later, defined by JSR 310. See Oracle Tutorial. And ThreeTen-Extra is a proving ground for possible future additions to java.time.
Both Joda-Time and java.time are led by the same man, Stephen Colbourne.
The Joda-Time team advises migration to java.time. Joda-Time is still actively supported for maintenance but any major new work will be put into java.time and ThreeTen-Extra instead of Joda-Time.