本文整理了Java中java.time.OffsetDateTime.parse()
方法的一些代码示例,展示了OffsetDateTime.parse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OffsetDateTime.parse()
方法的具体详情如下:
包路径:java.time.OffsetDateTime
类名称:OffsetDateTime
方法名:parse
[英]Obtains an instance of OffsetDateTime from a text string such as 2007-12-03T10:15:30+01:00.
The string must represent a valid date-time and is parsed using java.time.format.DateTimeFormatters#isoOffsetDateTime().
[中]从文本字符串(如2007-12-03T10:15:30+01:00)获取OffsetDateTime的实例。
字符串必须表示有效的日期和时间,并使用java进行解析。时间总体安排DateTimeFormatters#IsOffsetDateTime()。
代码示例来源:origin: org.assertj/assertj-core
/**
* {@inheritDoc}
*/
@Override
protected OffsetDateTime parse(String offsetDateTimeAsString) {
return OffsetDateTime.parse(offsetDateTimeAsString);
}
代码示例来源:origin: org.assertj/assertj-core
private static Object[] convertToOffsetDateTimeArray(String... dateTimesAsString) {
OffsetDateTime[] dates = new OffsetDateTime[dateTimesAsString.length];
for (int i = 0; i < dateTimesAsString.length; i++) {
dates[i] = OffsetDateTime.parse(dateTimesAsString[i]);
}
return dates;
}
代码示例来源:origin: joel-costigliola/assertj-core
private static Object[] convertToOffsetDateTimeArray(String... dateTimesAsString) {
OffsetDateTime[] dates = new OffsetDateTime[dateTimesAsString.length];
for (int i = 0; i < dateTimesAsString.length; i++) {
dates[i] = OffsetDateTime.parse(dateTimesAsString[i]);
}
return dates;
}
代码示例来源:origin: joel-costigliola/assertj-core
/**
* {@inheritDoc}
*/
@Override
protected OffsetDateTime parse(String offsetDateTimeAsString) {
return OffsetDateTime.parse(offsetDateTimeAsString);
}
代码示例来源:origin: dropwizard/dropwizard
@Override
protected OffsetDateTime parse(@Nullable final String input) throws Exception {
return OffsetDateTime.parse(input);
}
}
代码示例来源:origin: oracle/helidon
/**
* Maps {@code stringValue} to {@code OffsetDateTime}.
*
* @param stringValue source value as a {@code String}
* @return mapped {@code stringValue} to {@code OffsetDateTime}
* @see OffsetDateTime#parse(CharSequence)
*/
public static OffsetDateTime toOffsetDateTime(String stringValue) {
return OffsetDateTime.parse(stringValue);
}
代码示例来源:origin: org.springframework.boot/spring-boot
@Override
public OffsetDateTime parse(String text, Locale locale) throws ParseException {
return OffsetDateTime.parse(text, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}
代码示例来源:origin: prestodb/presto
@Override
protected OffsetDateTime deserialize(String key, DeserializationContext ctxt) throws IOException {
try {
return OffsetDateTime.parse(key, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
} catch (DateTimeException e) {
return _handleDateTimeException(ctxt, OffsetDateTime.class, e, key);
}
}
}
代码示例来源:origin: codecentric/spring-boot-admin
@Nullable
private static Instant getInstant(Object o) {
try {
if (o instanceof String) {
return OffsetDateTime.parse((String) o, TIMESTAMP_PATTERN).toInstant();
} else if (o instanceof Long) {
return Instant.ofEpochMilli((Long) o);
}
} catch (DateTimeException | ClassCastException e) {
return null;
}
return null;
}
}
代码示例来源:origin: SonarSource/sonarqube
/**
* @param s string in format {@link #DATETIME_FORMAT}
* @throws SonarException when string cannot be parsed
* @since 6.6
*/
public static OffsetDateTime parseOffsetDateTime(String s) {
try {
return OffsetDateTime.parse(s, DATETIME_FORMATTER);
} catch (DateTimeParseException e) {
throw MessageException.of("The date '" + s + "' does not respect format '" + DATETIME_FORMAT + "'", e);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public TemporalAccessor parse(String text, Locale locale) throws ParseException {
DateTimeFormatter formatterToUse = DateTimeContextHolder.getFormatter(this.formatter, locale);
if (LocalDate.class == this.temporalAccessorType) {
return LocalDate.parse(text, formatterToUse);
}
else if (LocalTime.class == this.temporalAccessorType) {
return LocalTime.parse(text, formatterToUse);
}
else if (LocalDateTime.class == this.temporalAccessorType) {
return LocalDateTime.parse(text, formatterToUse);
}
else if (ZonedDateTime.class == this.temporalAccessorType) {
return ZonedDateTime.parse(text, formatterToUse);
}
else if (OffsetDateTime.class == this.temporalAccessorType) {
return OffsetDateTime.parse(text, formatterToUse);
}
else if (OffsetTime.class == this.temporalAccessorType) {
return OffsetTime.parse(text, formatterToUse);
}
else {
throw new IllegalStateException("Unsupported TemporalAccessor type: " + this.temporalAccessorType);
}
}
代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-jsr310
@Override
protected OffsetDateTime deserialize(String key, DeserializationContext ctxt) throws IOException {
try {
return OffsetDateTime.parse(key, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
} catch (DateTimeException e) {
return _handleDateTimeException(ctxt, OffsetDateTime.class, e, key);
}
}
}
代码示例来源:origin: kiegroup/jbpm
public static long parseDateTime(String dateTimeStr) {
OffsetDateTime dateTime = OffsetDateTime.parse(dateTimeStr, DateTimeFormatter.ISO_DATE_TIME);
return dateTime.toInstant().toEpochMilli();
}
代码示例来源:origin: knowm/XChange
public static Date toDate(String dateString) {
try {
return dateParserNoMillis().parse(dateString);
} catch (ParseException e) {
OffsetDateTime offsetDateTime = OffsetDateTime.parse(dateString);
return new Date(offsetDateTime.toInstant().toEpochMilli());
}
}
代码示例来源:origin: org.springframework/spring-context
@Override
public TemporalAccessor parse(String text, Locale locale) throws ParseException {
DateTimeFormatter formatterToUse = DateTimeContextHolder.getFormatter(this.formatter, locale);
if (LocalDate.class == this.temporalAccessorType) {
return LocalDate.parse(text, formatterToUse);
}
else if (LocalTime.class == this.temporalAccessorType) {
return LocalTime.parse(text, formatterToUse);
}
else if (LocalDateTime.class == this.temporalAccessorType) {
return LocalDateTime.parse(text, formatterToUse);
}
else if (ZonedDateTime.class == this.temporalAccessorType) {
return ZonedDateTime.parse(text, formatterToUse);
}
else if (OffsetDateTime.class == this.temporalAccessorType) {
return OffsetDateTime.parse(text, formatterToUse);
}
else if (OffsetTime.class == this.temporalAccessorType) {
return OffsetTime.parse(text, formatterToUse);
}
else {
throw new IllegalStateException("Unsupported TemporalAccessor type: " + this.temporalAccessorType);
}
}
代码示例来源:origin: kiegroup/jbpm
public static long parseDateAsDuration(String dateTimeStr) {
try {
OffsetDateTime dateTime = OffsetDateTime.parse(dateTimeStr, DateTimeFormatter.ISO_DATE_TIME);
Duration duration = Duration.between(OffsetDateTime.now(), dateTime);
return duration.toMillis();
} catch (Exception e) {
return TimeUtils.parseTimeString(dateTimeStr);
}
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
@Override
public Object fromString(final String str) {
try {
return OffsetDateTime.parse(str);
} catch (final DateTimeParseException e) {
final ConversionException exception = new ConversionException("Cannot parse value as offset date time", e);
exception.add("value", str);
throw exception;
}
}
代码示例来源:origin: google/data-transfer-project
private static CalendarEventModel.CalendarEventTime getEventTime(EventDateTime dateTime) {
if (dateTime == null) {
return null;
}
OffsetDateTime offsetDateTime;
if (dateTime.getDate() == null) {
offsetDateTime = OffsetDateTime.parse(dateTime.getDateTime().toString());
} else {
offsetDateTime =
OffsetDateTime.from(
LocalDate.parse(dateTime.getDate().toString()).atStartOfDay(ZoneId.of("UTC")));
}
return new CalendarEventModel.CalendarEventTime(offsetDateTime, dateTime.getDate() != null);
}
代码示例来源:origin: alibaba/fastjson
OffsetDateTime offsetDateTime = OffsetDateTime.parse(text);
代码示例来源:origin: jdbi/jdbi
@Override
public void logBeforeExecution(StatementContext ctx) {
String toString = ctx.getBinding()
.findForName(name, ctx)
.orElseThrow(AssertionError::new)
.toString();
insertedTimestamp = OffsetDateTime.parse(toString);
insertedSqlTimestamp = Timestamp.from(insertedTimestamp.toInstant());
}
内容来源于网络,如有侵权,请联系作者删除!