Package java.time

Examples of java.time.LocalTime


   * @return
   */
  public static LocalTime createLocalTimeFromCalendar(Calendar calendar)
  {
    if (calendar == null) return null;
    LocalTime lLocalTime = LocalTime.of(calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND), calendar.get(Calendar.MILLISECOND) * 1000000);
    return lLocalTime;
  }
View Full Code Here


   */
  public static LocalTime createLocaleTimeFromDate(Date date) {
    if (date == null) {
      return null;
    }
    LocalTime lLocalTime = LocalTime.of( date.getHours(), date.getMinutes(), date.getSeconds(), 0 );
    return lLocalTime;
  }
View Full Code Here

    }
    final private DateTimeFormatter dateTimeFormatter;
   
    @Override
    public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
      LocalTime lLocalTime = createLocaleTimeFromDate(date);
      String s = this.dateTimeFormatter.format( lLocalTime );
      toAppendTo.append(s);
      return toAppendTo;
    }
View Full Code Here

      return toAppendTo;
    }

    @Override
    public Date parse(String source, ParsePosition pos) {
      LocalTime lLocalTime = LocalTime.parse(source, this.dateTimeFormatter);
      Date lDate = createDateFromLocalTime(lLocalTime);
      pos.setIndex(source.length()); // otherwise DateFormat will thrown an exception
      return lDate;
    }
View Full Code Here

    @Test
    public void testStringToLocalTime() {
        String dateTimeAsString = "00:00";
        Target target = new Target();
        target.setLocalTime( dateTimeAsString );
        LocalTime sourceTime =
                        LocalTime.of( 0, 0 );

        Source src = SourceTargetMapper.INSTANCE.targetToSourceLocalTimeMapped( target );
        assertThat( src ).isNotNull();
        assertThat( src.getLocalTime() ).isEqualTo( sourceTime );
View Full Code Here

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

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

        System.out.println(zone1.getRules());
        System.out.println(zone2.getRules());

        // time
        LocalTime now1 = LocalTime.now(zone1);
        LocalTime now2 = LocalTime.now(zone2);

        System.out.println(now1);
        System.out.println(now2);

        System.out.println(now1.isBefore(now2))// false

        long hoursBetween = ChronoUnit.HOURS.between(now1, now2);
        long minutesBetween = ChronoUnit.MINUTES.between(now1, now2);
        System.out.println(hoursBetween);
        System.out.println(minutesBetween);


        // create time

        LocalTime now = LocalTime.now();
        System.out.println(now);

        LocalTime late = LocalTime.of(23, 59, 59);
        System.out.println(late);

        DateTimeFormatter germanFormatter =
                DateTimeFormatter
                        .ofLocalizedTime(FormatStyle.SHORT)
                        .withLocale(Locale.GERMAN);

        LocalTime leetTime = LocalTime.parse("13:37", germanFormatter);
        System.out.println(leetTime);


        // to legacy date
View Full Code Here

            updateTime();
        }
    }
   
    private void updateTime() {
        LocalTime TIME = getSkinnable().getTime();
        // Seconds
        if (getSkinnable().isDiscreteSecond()) {
            secondRotate.setAngle(TIME.getSecond() * 6);
        } else {
            secondRotate.setAngle(TIME.getSecond() * 6 + TIME.get(ChronoField.MILLI_OF_SECOND) * 0.006);
        }
        // Minutes
        minuteAngle.set(TIME.getMinute() * 6);
        // Hours               
        hourRotate.setAngle(0.5 * (60 * TIME.getHour() + TIME.getMinute()));
       
        if (getSkinnable().isAutoNightMode()) checkForNight(TIME);
    }
View Full Code Here

    }

    private void updateClock() {
        time.setLength(0);

        LocalTime now = LocalTime.now();

        pm = now.get(ChronoField.AMPM_OF_DAY) == 1;
        hours.set(now.getHour());
        String hourString = Integer.toString(hours.get());
        if (hours.get() < 10) {
            time.append("0");
            time.append(hourString.substring(0, 1));
        } else {
            time.append(hourString.substring(0, 1));
            time.append(hourString.substring(1));
        }

        time.append(":");

        minutes.set(now.getMinute());
        String minutesString = Integer.toString(minutes.get());
        if (minutes.get() < 10) {
            time.append("0");
            time.append(minutesString.substring(0, 1));
        } else {
            time.append(minutesString.substring(0, 1));
            time.append(minutesString.substring(1));
        }

        seconds.set(now.getSecond());
       
        if (isAlarmOn() && now.isAfter(getAlarm()) && now.isBefore(getAlarm().plusNanos(105_000_000))) {
            fireAlarmEvent();
        }
    }
View Full Code Here

    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()
    LocalDateTime futureDateTime = localDateTime.plusWeeks(3);
View Full Code Here

TOP

Related Classes of java.time.LocalTime

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.