예제 #1
0
  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);
  }
예제 #2
0
  public void localDateTimeTest() {
    LocalDateTime currentTime = LocalDateTime.now();

    System.out.println(currentTime);

    System.out.println(currentTime.format(formatter));
  }
 private String[] setCustomTime(String requestUid, String userInput, User user) {
   LocalDateTime parsedTime = eventUtil.parseDateTime(userInput);
   userLogger.recordUserInputtedDateTime(
       user.getUid(), userInput, "vote-custom", UserInterfaceType.USSD);
   eventRequestBroker.updateEventDateTime(user.getUid(), requestUid, parsedTime);
   final String dateTimePrompt = "at " + parsedTime.format(dateTimeFormat);
   return new String[] {eventRequestBroker.load(requestUid).getName(), dateTimePrompt};
 }
예제 #4
0
    @Override
    protected void updateItem(LocalDateTime item, boolean empty) {
      super.updateItem(item, empty);

      if (!empty) {
        setText(item.format(DateTimeFormatter.ISO_LOCAL_DATE));
      } else {
        setText(null);
      }
    }
/** @author maxrenet */
public class DateExample {

  static LocalDate one = LocalDate.now();
  static LocalDateTime two = LocalDateTime.now();
  static LocalTime three = LocalTime.now();
  static String dateOne = one.format(DateTimeFormatter.ISO_DATE);
  static String dateTwo = two.format(DateTimeFormatter.ISO_DATE);
  static String dateThree = two.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT));
  static String dateFour = two.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM));
  static String dateFive = two.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG));
  // static String timeThree=three.format(DateTimeFormatter.ISO_LOCAL_TIME);
  public static void main(String[] args) {
    System.out.println(two);
    System.out.println("ISODATE returns " + dateTwo);
    System.out.println("Short date returns " + dateThree);
    System.out.println("Medium date returns: " + dateFour);
    System.out.println("Long date returns: " + dateFive);
  }
}
  private void validateIntervalPosition(ConferenceInterval interval) {
    LocalDateTime startDateTime = interval.getStartDateTime();
    LocalDateTime endDateTime = interval.getEndDateTime();
    LocalDateTime now = LocalDateTime.now();

    LocalDateTime minStartDateTime = now.plusDays(MIN_TIME_BEFORE_CONFERENCE_START_IN_DAYS);

    if (startDateTime.isBefore(minStartDateTime)) {
      throw new ValidationException(
          String.format(
              "Conference must start after %s",
              minStartDateTime.format(CONFERENCE_DATE_TIME_FORMATTER)));
    }

    if (endDateTime.isBefore(startDateTime)) {
      throw new ValidationException(
          String.format(
              "Conference end dateTime %s is before start dateTime %s",
              endDateTime.format(CONFERENCE_DATE_TIME_FORMATTER),
              startDateTime.format(CONFERENCE_DATE_TIME_FORMATTER)));
    }
  }
  /**
   * Uses <code>List workoutHistoryLog</code> to build the bar chart series:
   *
   * <ul>
   *   <li>Selects the last 7 days of workout history
   *   <li>retrieves history data and formats dates for <code>xDateAxis</code> and total workout
   *       time for that day for the <code>yWorkoutTimeAxis</code>
   *   <li>adds all data to the series
   * </ul>
   */
  private void makeWeekSeriesFromAccountHistory() {

    Locale eng = Locale.UK;
    LocalDateTime today = LocalDateTime.now();

    String inputPattern = "yyyyMMddHHmm";
    DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern(inputPattern, eng);

    String outputPattern = "EEEE"; // day with text
    DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputPattern, eng);

    // Variables for history entries
    String inputDate;
    long timeToComplete;

    // LocalDateTime object for input date
    LocalDateTime dateOfCompletion;
    // String output for axis
    String formattedDateForAxis;

    long lastDate;

    // Search all workout entries in account's workout history
    // parse the input date string into a LocalDateTime for pattern formatting
    // find entries that are within the last week
    // add date against workout time to series
    for (WorkoutEntry entry : workoutHistoryLog) {

      // Get workout date from history entry
      inputDate = entry.getWorkoutDate();
      dateOfCompletion = LocalDateTime.parse(inputDate, inputFormatter);

      formattedDateForAxis = dateOfCompletion.format(outputFormatter);

      // Check if within the last 7 days
      if (dateOfCompletion.until(today, ChronoUnit.WEEKS) == 0) {
        timeToComplete = entry.getWorkoutTime();
        seriesW.getData().add(new XYChart.Data(formattedDateForAxis, timeToComplete));
      }
    }
  }
예제 #8
0
 public Path buildLogFile(final String filePrefix) throws IOException {
   LocalDateTime now = LocalDateTime.now();
   Path dir = Paths.get("reports", now.format(ofPattern("yyyyMMdd")));
   Files.createDirectories(dir);
   return Paths.get(dir.toString(), filePrefix + now.format(ofPattern("HHmm")) + ".txt");
 }
 @Override
 public String serialize(LocalDateTime t) {
   return t.format(this.formatter);
 }
  /**
   * Uses <code>List workoutHistoryLog</code> to build the bar chart series:
   *
   * <ul>
   *   <li>Selects the last 30 days of workout history
   *   <li>retrieves history data and formats dates for <code>xDateAxis</code> and total workout
   *       time for that day for the <code>yWorkoutTimeAxis</code>
   *   <li>adds all data to the series
   * </ul>
   */
  private void makeMonthSeriesFromAccountHistory() {

    Locale eng = Locale.UK;
    LocalDateTime today = LocalDateTime.now();

    String inputPattern = "yyyyMMddHHmm";
    DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern(inputPattern, eng);

    String outputPattern = "dd/MM"; // day with text
    DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputPattern, eng);

    // Variables for history entries
    String inputDate;
    long timeToComplete;
    long input;

    // LocalDateTime object for input date
    LocalDateTime dateOfCompletion;
    // LocalDateTime newDate = LocalDateTime.of(1900, 05, 16, 03);

    // String output for axis
    String formattedDateForAxis;

    // Search all workout entries in account's workout history
    // parse the input date string into a LocalDateTime for pattern formatting
    // find entries that are within the last week
    // add date against workout time to series
    for (int i = 0; i < workoutHistoryLog.size(); i++) {

      // Get workout date from history entry
      inputDate = workoutHistoryLog.get(i).getWorkoutDate();
      // input = Long.parseLong(inputDate);

      dateOfCompletion = LocalDateTime.parse(inputDate, inputFormatter);

      formattedDateForAxis = dateOfCompletion.format(outputFormatter);

      // Check if within the last month
      if (dateOfCompletion.until(today, ChronoUnit.MONTHS) == 0) {

        timeToComplete = workoutHistoryLog.get(i).getWorkoutTime();

        seriesM.getData().add(new XYChart.Data(formattedDateForAxis, timeToComplete));

        if (i != workoutHistoryLog.size() - 1) {
          int diff = getDifference(inputDate, workoutHistoryLog.get(i + 1).getWorkoutDate());
          LocalDateTime noWorkoutDate = dateOfCompletion;

          if (diff > 1) {
            for (int j = 0; j < diff - 1; j++) {
              noWorkoutDate.plusDays(j + 1);
              System.out.println(noWorkoutDate.plusDays(j + 1).format(outputFormatter));
              seriesM
                  .getData()
                  .add(new XYChart.Data(noWorkoutDate.plusDays(j + 1).format(outputFormatter), 0));
            }
            System.out.println("out");
          }
        }
      }
    }
  }
예제 #11
0
 public String getTimeText() {
   final Instant safe_time = time;
   if (safe_time == null) return "";
   final LocalDateTime local = LocalDateTime.ofInstant(safe_time, ZoneId.systemDefault());
   return local.format(formatter);
 }
예제 #12
0
 public String getMercDtTm() {
   return MercDtTm.format(DateTimeFormatter.ofPattern("yyyyMMddhhmmss"));
 }