public static void main(String[] args) {
    LocalDate hoje = LocalDate.now();
    System.out.println(hoje);

    LocalDate olimpiadasRio = LocalDate.of(2016, Month.JUNE, 5);
    System.out.println(olimpiadasRio);

    int dias = olimpiadasRio.getDayOfYear() - hoje.getDayOfYear();
    System.out.println(dias + " dias para as Olímpiadas no Rio!");

    Period periodo = Period.between(hoje, olimpiadasRio);
    System.out.println(periodo.getMonths() + " meses e " + periodo.getDays() + " dias.");

    DateTimeFormatter formatador = DateTimeFormatter.ofPattern("dd/MM/yyyy");
    String valorFormatado = olimpiadasRio.format(formatador);
    System.out.println(valorFormatado);

    System.out.println(" --- Medida de tempo ---");

    DateTimeFormatter formatadorComHoras = DateTimeFormatter.ofPattern("dd/MM/yyyy hh:mm:ss");
    LocalDateTime agora = LocalDateTime.now();
    System.out.println(agora);
    System.out.println(agora.format(formatadorComHoras));

    LocalTime intervalo = LocalTime.of(12, 30);
    System.out.println(intervalo);
  }
 @Override
 public boolean includes(Date date) {
   Instant instant = Instant.ofEpochMilli(date.getTime());
   LocalDate localDate = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalDate();
   return localDate.getDayOfYear() == 1;
 }
  private Day create(final LocalDate localDay) {

    log.debug("Entering with {}", localDay);

    return new Day(localDay.getDayOfWeek(), localDay.getDayOfMonth(), localDay.getDayOfYear());
  }
  BudgetPeriodDescriptor(
      final LocalDate budgetDate, final int budgetYear, final BudgetPeriod budgetPeriod) {
    Objects.requireNonNull(budgetPeriod);
    Objects.requireNonNull(budgetDate);

    this.budgetYear = budgetYear;
    this.budgetPeriod = budgetPeriod;
    this.startPeriod = budgetDate.getDayOfYear() - 1; // zero based index vs. 1 based day of year

    /* Calendar day 1 is 1.  Need to add 1 to get correct dates */
    startDate = LocalDate.ofYearDay(budgetYear, startPeriod + 1);

    switch (budgetPeriod) {
      case DAILY:
        endDate = startDate;
        endPeriod = startPeriod;

        periodDescription =
            ResourceUtils.getString("Pattern.NumericDate", DateUtils.asDate(startDate));
        break;
      case WEEKLY:
        // Check to see if we are working with the start of a 53 week year.  The first week will be
        // truncated
        if (DateUtils.getNumberOfWeeksInYear(budgetYear) == DateUtils.LEAP_WEEK
            && budgetDate.getYear() < budgetYear) {
          startPeriod = 0;
          startDate = budgetDate;

          endPeriod =
              (int) ChronoUnit.DAYS.between(startDate, LocalDate.of(budgetYear, Month.JANUARY, 1));
          endDate = startDate.plusDays(ONE_WEEK_INCREMENT);
        } else {
          endDate = startDate.plusDays(ONE_WEEK_INCREMENT);
          endPeriod =
              Math.min(
                  startPeriod + ONE_WEEK_INCREMENT,
                  BudgetGoal.PERIODS - 1); // need to cap for 53 week years
        }

        periodDescription =
            ResourceUtils.getString(
                "Pattern.WeekOfYear", DateUtils.getWeekOfTheYear(startDate), budgetYear);
        break;
      case BI_WEEKLY:
        if (DateUtils.getWeekOfTheYear(startDate) != DateUtils.LEAP_WEEK) {
          endDate = startDate.plusDays(TWO_WEEK_INCREMENT);
          endPeriod = startPeriod + TWO_WEEK_INCREMENT;
        } else {
          endDate = startDate.plusDays(ONE_WEEK_INCREMENT);
          endPeriod = startPeriod + ONE_WEEK_INCREMENT;
        }
        periodDescription =
            ResourceUtils.getString(
                "Pattern.DateRangeShort", DateUtils.asDate(startDate), DateUtils.asDate(endDate));
        break;
      case MONTHLY:
        final int days = startDate.lengthOfMonth();
        endDate = DateUtils.getLastDayOfTheMonth(startDate);
        endPeriod = startPeriod + days - 1;

        periodDescription =
            ResourceUtils.getString("Pattern.MonthOfYear", DateUtils.asDate(startDate));
        break;
      case QUARTERLY:
        endDate = DateUtils.getLastDayOfTheQuarter(startDate);
        endPeriod = startPeriod + (int) ChronoUnit.DAYS.between(startDate, endDate);

        periodDescription =
            ResourceUtils.getString(
                "Pattern.QuarterOfYear", DateUtils.getQuarterNumber(startDate), budgetYear);
        break;
      case YEARLY:
        endDate = DateUtils.getLastDayOfTheYear(startDate);
        endPeriod = startPeriod + (int) ChronoUnit.DAYS.between(startDate, endDate);

        periodDescription = Integer.toString(budgetYear);
        break;
      default:
        endPeriod = startPeriod;
        endDate = LocalDate.now();
        periodDescription = "";
    }

    // Periods especially bi-weekly can get weird, correct ending period if needed.
    if (endPeriod > BudgetGoal.PERIODS) {
      endPeriod = BudgetGoal.PERIODS - 1;
      endDate = DateUtils.getLastDayOfTheYear(startDate);
    }
  }