Package java.time

Examples of java.time.Instant


                    if (zid == null) {
                        throw new IllegalFormatConversionException(c, t.getClass());
                    }
                    if (!(zid instanceof ZoneOffset) &&
                        t.isSupported(ChronoField.INSTANT_SECONDS)) {
                        Instant instant = Instant.from(t);
                        sb.append(TimeZone.getTimeZone(zid.getId())
                                          .getDisplayName(zid.getRules().isDaylightSavings(instant),
                                                          TimeZone.SHORT,
                                                          (l == null) ? Locale.US : l));
                        break;
View Full Code Here


     */
    default ChronoZonedDateTime<? extends ChronoLocalDate> zonedDateTime(TemporalAccessor temporal) {
        try {
            ZoneId zone = ZoneId.from(temporal);
            try {
                Instant instant = Instant.from(temporal);
                return zonedDateTime(instant, zone);

            } catch (DateTimeException ex1) {
                ChronoLocalDateTimeImpl<?> cldt = ChronoLocalDateTimeImpl.ensureValid(this, localDateTime(temporal));
                return ChronoZonedDateTimeImpl.ofBest(cldt, zone, null);
View Full Code Here

   */
  public static Date createDateFromLocalDate(LocalDate localDate) {
    if (localDate == null) {
      return null;
    }
    Instant lInstant = localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
    Date lDate = Date.from(lInstant);
    return lDate;
  }
View Full Code Here

   */
  public static Date createDateFromLocalDateTime(LocalDateTime localDateTime) {
    if (localDateTime == null) {
      return null;
    }
    Instant lInstant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
    Date lDate = Date.from(lInstant);
    return lDate;
  }
View Full Code Here

            } else if (type == Duration.class) {
                Duration duration = Duration.parse(text);
               
                return (T) duration;
            } else if (type == Instant.class) {
                Instant instant = Instant.parse(text);
               
                return (T) instant;
            }
        } else {
            throw new UnsupportedOperationException();
View Full Code Here

   }

   @SuppressWarnings("deprecation")
   private Sale createSale(Customer customer, int year, int month, int day, int hour)
   {
      Instant instant = LocalDateTime.of(year, month, day, hour, 0).toInstant(ZoneOffset.UTC);
      Date date = Date.from(instant);
      Calendar cal = Calendar.getInstance();
      cal.setTime(date);
      // SQL and JPA has some issues with timezones, so we'll manually
      // set the years and stuff for dates using deprecated methods to
View Full Code Here

      return createSale(customer, year, 1, 1, 1);
   }

   private Sale createSale(Customer customer, int year, int month, int day, int hour)
   {
      Instant instant = LocalDateTime.of(year, month, day, hour, 0).toInstant(ZoneOffset.UTC);
      Date date = Date.from(instant);
     
      Sale s = new Sale();
      s.setDate(date);
      s.setCustomer(customer);
View Full Code Here

    constraint = new PastValidatorForInstant();
  }

  @Test
  public void testIsValid() {
    Instant future = Instant.now().plusSeconds( 3600 );
    Instant past = Instant.now().minusSeconds( 3600 );

    assertTrue( constraint.isValid( null, null ), "null fails validation." );
    assertTrue( constraint.isValid( past, null ), "Past Instant '" + past + "' fails validation.");
    assertFalse( constraint.isValid( future, null ), "Future Instant '" + future + "' validated as past.");
  }
View Full Code Here

    constraint = new FutureValidatorForInstant();
  }

  @Test
  public void testIsValid() {
    Instant future = Instant.now().plusSeconds( 3600 );
    Instant past = Instant.now().minusSeconds( 3600 );

    assertTrue( constraint.isValid( null, null ), "null fails validation." );
    assertTrue( constraint.isValid( future, null ), "Future Instant '" + future + "' fails validation.");
    assertFalse( constraint.isValid( past, null ), "Past Instant '" + past + "' validated as future.");
  }
View Full Code Here

        // get the current time
        Clock clock = Clock.systemDefaultZone();
        long t0 = clock.millis();
        System.out.println(t0);

        Instant instant = clock.instant();
        Date legacyDate = Date.from(instant);


        ZoneId zone1 = ZoneId.of("Europe/Berlin");
        ZoneId zone2 = ZoneId.of("Brazil/East");
View Full Code Here

TOP

Related Classes of java.time.Instant

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.