org.threeten.bp.OffsetDateTime.parse()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(196)

本文整理了Java中org.threeten.bp.OffsetDateTime.parse()方法的一些代码示例,展示了OffsetDateTime.parse()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OffsetDateTime.parse()方法的具体详情如下:
包路径:org.threeten.bp.OffsetDateTime
类名称:OffsetDateTime
方法名:parse

OffsetDateTime.parse介绍

[英]Obtains an instance of OffsetDateTime from a text string such as 2007-12-23T10:15:30+01:00.

The string must represent a valid date-time and is parsed using org.threeten.bp.format.DateTimeFormatter#ISO_OFFSET_DATE_TIME.
[中]从文本字符串(如2007-12-23T10:15:30+01:00)获取OffsetDateTime的实例。
字符串必须表示有效的日期和时间,并使用org解析。三十。英国石油公司。总体安排DateTimeFormatter#ISO_OFFSET _DATE_TIME。

代码示例

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Obtains an instance of {@code OffsetDateTime} from a text string
 * such as {@code 2007-12-23T10:15:30+01:00}.
 * <p>
 * The string must represent a valid date-time and is parsed using
 * {@link org.threeten.bp.format.DateTimeFormatter#ISO_OFFSET_DATE_TIME}.
 *
 * @param text  the text to parse such as "2007-12-23T10:15:30+01:00", not null
 * @return the parsed offset date-time, not null
 * @throws DateTimeParseException if the text cannot be parsed
 */
public static OffsetDateTime parse(CharSequence text) {
  return parse(text, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Obtains an instance of {@code OffsetDateTime} from a text string
 * such as {@code 2007-12-03T10:15:30+01:00}.
 * <p>
 * The string must represent a valid date-time and is parsed using
 * {@link org.threeten.bp.format.DateTimeFormatter#ISO_OFFSET_DATE_TIME}.
 *
 * @param text  the text to parse such as "2007-12-03T10:15:30+01:00", not null
 * @return the parsed offset date-time, not null
 * @throws DateTimeParseException if the text cannot be parsed
 */
public static OffsetDateTime parse(CharSequence text) {
  return parse(text, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}

代码示例来源:origin: gengstrand/clojure-news-feed

default OffsetDateTime convert(long time) {
    return OffsetDateTime.parse(sdf.format(new Date(time)));
  }
}

代码示例来源:origin: com.github.joschi.jackson/jackson-datatype-threetenbp

@Override
  protected OffsetDateTime deserialize(String key, DeserializationContext ctxt) throws IOException {
    try {
      return OffsetDateTime.parse(key, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
    } catch (DateTimeException e) {
      return _rethrowDateTimeException(ctxt, OffsetDateTime.class, e, key);
    }
  }
}

代码示例来源:origin: gotify/android

@Override
  public OffsetDateTime read(JsonReader in) throws IOException {
    switch (in.peek()) {
      case NULL:
        in.nextNull();
        return null;
      default:
        String date = in.nextString();
        if (date.endsWith("+0000")) {
          date = date.substring(0, date.length()-5) + "Z";
        }
        return OffsetDateTime.parse(date, formatter);
    }
  }
}

代码示例来源:origin: com.neotys.ascode/swagger-java-client

@Override
  public OffsetDateTime read(JsonReader in) throws IOException {
    switch (in.peek()) {
      case NULL:
        in.nextNull();
        return null;
      default:
        String date = in.nextString();
        if (date.endsWith("+0000")) {
          date = date.substring(0, date.length()-5) + "Z";
        }
        return OffsetDateTime.parse(date, formatter);
    }
  }
}

代码示例来源:origin: com.graphhopper/directions-api-client

@Override
  public OffsetDateTime read(JsonReader in) throws IOException {
    switch (in.peek()) {
      case NULL:
        in.nextNull();
        return null;
      default:
        String date = in.nextString();
        if (date.endsWith("+0000")) {
          date = date.substring(0, date.length()-5) + "Z";
        }
        return OffsetDateTime.parse(date, formatter);
    }
  }
}

代码示例来源:origin: de.adorsys.multibanking/finapi-adapter

@Override
  public OffsetDateTime read(JsonReader in) throws IOException {
    switch (in.peek()) {
      case NULL:
        in.nextNull();
        return null;
      default:
        String date = in.nextString();
        if (date.endsWith("+0000")) {
          date = date.substring(0, date.length()-5) + "Z";
        }
        return OffsetDateTime.parse(date, formatter);
    }
  }
}

代码示例来源:origin: org.renci.io.swagger/swagger-java-comet-client

@Override
  public OffsetDateTime read(JsonReader in) throws IOException {
    switch (in.peek()) {
      case NULL:
        in.nextNull();
        return null;
      default:
        String date = in.nextString();
        if (date.endsWith("+0000")) {
          date = date.substring(0, date.length()-5) + "Z";
        }
        return OffsetDateTime.parse(date, formatter);
    }
  }
}

代码示例来源:origin: AzureAD/azure-activedirectory-library-for-android

@Override
  public OffsetDateTime read(JsonReader in) throws IOException {
    switch (in.peek()) {
      case NULL:
        in.nextNull();
        return null;
      default:
        String date = in.nextString();
        if (date.endsWith("+0000")) {
          date = date.substring(0, date.length()-5) + "Z";
        }
        return OffsetDateTime.parse(date, formatter);
    }
  }
}

代码示例来源:origin: AzureAD/azure-activedirectory-library-for-android

@Override
  public OffsetDateTime read(JsonReader in) throws IOException {
    switch (in.peek()) {
      case NULL:
        in.nextNull();
        return null;
      default:
        String date = in.nextString();
        if (date.endsWith("+0000")) {
          date = date.substring(0, date.length()-5) + "Z";
        }
        return OffsetDateTime.parse(date, formatter);
    }
  }
}

代码示例来源:origin: shinesolutions/swagger-aem

@Override
  public OffsetDateTime read(JsonReader in) throws IOException {
    switch (in.peek()) {
      case NULL:
        in.nextNull();
        return null;
      default:
        String date = in.nextString();
        if (date.endsWith("+0000")) {
          date = date.substring(0, date.length()-5) + "Z";
        }
        return OffsetDateTime.parse(date, formatter);
    }
  }
}

代码示例来源:origin: com.uwetrottmann.trakt5/trakt-java

public static GsonBuilder getGsonBuilder() {
  GsonBuilder builder = new GsonBuilder();
  // trakt exclusively uses ISO 8601 date times with milliseconds and time zone offset
  // such as '2011-12-03T10:15:30.000+01:00' or '2011-12-03T10:15:30.000Z'
  builder.registerTypeAdapter(OffsetDateTime.class,
      (JsonDeserializer<OffsetDateTime>) (json, typeOfT, context) -> OffsetDateTime.parse(json.getAsString()));
  builder.registerTypeAdapter(OffsetDateTime.class,
      (JsonSerializer<OffsetDateTime>) (src, typeOfSrc, context) -> new JsonPrimitive(src.toString()));
  // dates are in ISO 8601 format as well
  builder.registerTypeAdapter(LocalDate.class,
      (JsonDeserializer<LocalDate>) (json, typeOfT, context) -> LocalDate.parse(json.getAsString()));
  // privacy
  builder.registerTypeAdapter(ListPrivacy.class,
      (JsonDeserializer<ListPrivacy>) (json, typeOfT, context) -> ListPrivacy.fromValue(json.getAsString()));
  // rating
  builder.registerTypeAdapter(Rating.class,
      (JsonDeserializer<Rating>) (json, typeOfT, context) -> Rating.fromValue(json.getAsInt()));
  builder.registerTypeAdapter(Rating.class,
      (JsonSerializer<Rating>) (src, typeOfSrc, context) -> new JsonPrimitive(src.value));
  // sort by
  builder.registerTypeAdapter(SortBy.class,
      (JsonDeserializer<SortBy>) (json, typeOfT, context) -> SortBy.fromValue(json.getAsString()));
  // sort how
  builder.registerTypeAdapter(SortHow.class,
      (JsonDeserializer<SortHow>) (json, typeOfT, context) -> SortHow.fromValue(json.getAsString()));
  // status
  builder.registerTypeAdapter(Status.class,
      (JsonDeserializer<Status>) (json, typeOfT, context) -> Status.fromValue(json.getAsString()));
  return builder;
}

代码示例来源:origin: alexvoronov/geonetworking

@Override
public LongPositionVector getLatestPosition() {
  Optional<Address> emptyAddress = Optional.empty();
  if (lastSeenTPV == null) {
    Instant timestamp = Instant.now();
    Position position = new Position(Double.NaN, Double.NaN);  // NaN or 0?
    boolean isPositionConfident = false;
    double speedMetersPerSecond = 0;
    double headingDegreesFromNorth = 0;
    return new LongPositionVector(emptyAddress, timestamp, position, isPositionConfident,
        speedMetersPerSecond, headingDegreesFromNorth);
  } else {
    final TPV tpv = lastSeenTPV;  // Is this enough to ensure that tpv will remain the same
                   // through the rest of the method?
    Instant timestamp = OffsetDateTime.parse(tpv.time()).toInstant();
    Position position = new Position(tpv.lat(), tpv.lon());
    boolean isPositionConfident = false;  // TODO: double-check conditions for PAI=true.
    double speedMetersPerSecond = tpv.speed();
    double headingDegreesFromNorth = tpv.track();
    return new LongPositionVector(emptyAddress, timestamp, position, isPositionConfident,
        speedMetersPerSecond, headingDegreesFromNorth);
  }
}

代码示例来源:origin: ngs-doo/dsl-json

return OffsetDateTime.parse(new String(tmp, 0, len));

相关文章