Package java.time

Examples of java.time.LocalDate


    Integer result = treble.apply(7);

    BinaryOperator<Integer> add = (a,b) -> a + b;
    Integer three = add.apply(1,2);

    LocalDate today = LocalDate.now();
    Function<LocalDate, String> tomorrow = d -> d.plusDays(1).getDayOfWeek().name();

    // Is UnaryOperator<Integer> a Function<Integer,Integer> ?

    BiFunction<LocalDate, LocalDate, Long> daysBetween =
View Full Code Here


            if (type == LocalDateTime.class) {
                LocalDateTime localDateTime = LocalDateTime.parse(text);

                return (T) localDateTime;
            } else if (type == LocalDate.class) {
                LocalDate localDate = LocalDate.parse(text);

                return (T) localDate;
            } else if (type == LocalTime.class) {
                LocalTime localDate = LocalTime.parse(text);
               
View Full Code Here

        try (PersistenceSession session = persistenceManager.createSession()) {
            JavatimeConvertEntity inst = new JavatimeConvertEntity();
            inst.setId(99);
            OffsetDateTime dt = OffsetDateTime.ofInstant(new Date().toInstant(), ZoneOffset.of("+0200"));
            LocalDateTime ldt = dt.toLocalDateTime();
            LocalDate ld = ldt.toLocalDate();
            inst.setDateTime(dt);
            inst.setLocalDate(ld);
            inst.setLocalDateTime(ldt);
            session.insert(inst);
View Full Code Here

  }
 
  @Override
  public void handle(ActionEvent arg0) {
    List<Object> arg = new LinkedList<Object>();
    LocalDate from = ((DatePicker)args.get(0)).getValue();
    LocalDate to = ((DatePicker)args.get(1)).getValue();
   
    if (from == null || to == null) {
      results.appendText("undefined from date or to date\n");
      return;
    }
    if (from.compareTo(to) >= 0) {
      results.appendText("from date >= to date\n");
      return;
    }
   
    arg.add(from.toString()); arg.add(to.toString());
    try {
      SQLQuery query = new HistorySearchQuery(connect, results);
      query.prepareQuery(arg);
      query.doQuery();
      query.close();
View Full Code Here

  }

  @Override
  public void handle(ActionEvent arg0) {
    List<Object> arg = new LinkedList<Object>();
    LocalDate from = ((DatePicker) args.get(0)).getValue();
    LocalDate to = ((DatePicker) args.get(1)).getValue();
    if (from == null || to == null) {
      results.appendText("undefined from date or to date\n");
      return;
    }
    if (from.compareTo(to) >= 0) {
      results.appendText("from date >= to date\n");
      return;
    }
    arg.add(from.toString()); arg.add(to.toString());
    try {
      SQLQuery query = new IncomeCalcQuery(connect, results);
      query.prepareQuery(arg);
      query.doQuery();
      query.close();
View Full Code Here

* @author Benjamin Winterberg
*/
public class LocalDate1 {

    public static void main(String[] args) {
        LocalDate today = LocalDate.now();
        LocalDate tomorrow = today.plus(1, ChronoUnit.DAYS);
        LocalDate yesterday = tomorrow.minusDays(2);

        System.out.println(today);
        System.out.println(tomorrow);
        System.out.println(yesterday);

        LocalDate independenceDay = LocalDate.of(2014, Month.JULY, 4);
        DayOfWeek dayOfWeek = independenceDay.getDayOfWeek();
        System.out.println(dayOfWeek);    // FRIDAY

        DateTimeFormatter germanFormatter =
                DateTimeFormatter
                        .ofLocalizedDate(FormatStyle.MEDIUM)
                        .withLocale(Locale.GERMAN);

        LocalDate xmas = LocalDate.parse("24.12.2014", germanFormatter);
        System.out.println(xmas);   // 2014-12-24


    }
View Full Code Here

    // Test altering component fields with literal values using withXXX()
    int pastYear = 2013;
    int pastDayOfMonth = 1;
    final LocalDateTime pastDateTime = localDateTime.withYear(pastYear).withDayOfMonth(pastDayOfMonth);
    // Construct separate LocalDate and Time from supplied component values, and time component of existing DateTime
    LocalDate expectedDate = LocalDate.of(pastYear, localDateTime.getMonth(), pastDayOfMonth);
    final LocalTime expectedTime = localDateTime.toLocalTime();
    // A LocalDateTime can be constructed from separate LocalDate and LocalTime
    assertThat(pastDateTime, is(LocalDateTime.of(expectedDate, expectedTime)));

    // Test altering component fields using delta method plusXXX()
View Full Code Here

    final Period period = Period.of(3, 2, 1);
    // Components of a Period are represented by ChronoUnit values
    assertThat(period.get(ChronoUnit.DAYS), is(1L));

    // You can modify the values of a Date using a Period
    final LocalDate localDate = LocalDate.of(2014, Month.SEPTEMBER, 1);
    final LocalDate futureDate = localDate.plus(period);
    assertThat(futureDate, is(LocalDate.of(2017, Month.NOVEMBER, 2)));
    // You can also use a Period to calculate the difference between two dates
    assertThat(Period.between(localDate, futureDate), is(period));

    final LocalDate pastDate = localDate.minus(period);
    assertThat(pastDate, is(LocalDate.of(2011, Month.JUNE, 30)));
  }
View Full Code Here

   * {@link java.time.MonthDay} is a holder for an associated month and day, such as a birthday.
   */
  @Test
  public void testMonthDayHolder() {
    final MonthDay birthday = MonthDay.of(Month.SEPTEMBER, 1);
    final LocalDate localDate = LocalDate.of(2014, birthday.getMonthValue(), birthday.getDayOfMonth());

    assertThat(localDate.getMonth(), is(birthday.getMonth()));
  }
View Full Code Here

   * {@link java.time.YearMonth} is a holder for an associated year and month, such as that used for expiry dates.
   */
  @Test
  public void testYearMonthHolder() {
    final YearMonth expiry = YearMonth.of(2014, Month.SEPTEMBER);
    final LocalDate localDate = LocalDate.of(expiry.getYear(), expiry.getMonthValue(), 1);

    assertThat(localDate.getMonth(), is(expiry.getMonth()));
  }
View Full Code Here

TOP

Related Classes of java.time.LocalDate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.