fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.time.*;
  4. import java.time.temporal.IsoFields;
  5.  
  6. /* Name of the class has to be "Main" only if the class is public. */
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. LocalDate now = LocalDate.now(ZoneId.of("Europe/London"));
  12. LocalDate toDisplay=now;
  13. System.out.printf("We're currently in %s Q%s%n", toDisplay.getYear(), toDisplay.get(IsoFields.QUARTER_OF_YEAR));
  14.  
  15. toDisplay = now.minus(1, IsoFields.QUARTER_YEARS);
  16. System.out.printf("1 quarter-of-year ago was %s Q%s, the date was %s%n", toDisplay.getYear(), toDisplay.get(IsoFields.QUARTER_OF_YEAR), toDisplay);
  17. toDisplay = now.minus(8, IsoFields.QUARTER_YEARS);
  18. System.out.printf("8 quarter-of-year ago was %s Q%s, the date was %s%n", toDisplay.getYear(), toDisplay.get(IsoFields.QUARTER_OF_YEAR), toDisplay);
  19. }
  20. }
Success #stdin #stdout 0.1s 36336KB
stdin
Standard input is empty
stdout
We're currently in 2019 Q3
1 quarter-of-year ago was 2019 Q2, the date was 2019-04-29
8 quarter-of-year ago was 2017 Q3, the date was 2017-07-29