Skip to content

Commit e7258a5

Browse files
New Examples
1 parent ce34998 commit e7258a5

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.howtodoinjava.core.datetime;
2+
3+
import java.time.LocalDate;
4+
import java.time.format.DateTimeFormatter;
5+
import java.time.temporal.IsoFields;
6+
import java.time.temporal.TemporalAdjusters;
7+
8+
public class GetQuarterInfo {
9+
10+
public static void main(String[] args) {
11+
12+
LocalDate localDate = LocalDate.now();
13+
14+
//What is current quarter
15+
int currentQuarter = localDate.get(IsoFields.QUARTER_OF_YEAR);
16+
System.out.println(currentQuarter);
17+
18+
String currentQuarterStr = localDate.format(DateTimeFormatter.ofPattern("QQQQ"));
19+
System.out.println(currentQuarterStr);
20+
21+
//Current quarter start date and end date
22+
LocalDate firstDay = localDate.with(IsoFields.DAY_OF_QUARTER, 1L);
23+
LocalDate lastDay = firstDay.plusMonths(2).with(TemporalAdjusters.lastDayOfMonth());
24+
System.out.println(firstDay);
25+
System.out.println(lastDay);
26+
}
27+
}

0 commit comments

Comments
 (0)