本文整理了Java中java.time.OffsetDateTime.toInstant()
方法的一些代码示例,展示了OffsetDateTime.toInstant()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OffsetDateTime.toInstant()
方法的具体详情如下:
包路径:java.time.OffsetDateTime
类名称:OffsetDateTime
方法名:toInstant
[英]Converts this date-time to an Instant.
[中]将此日期时间转换为瞬间。
代码示例来源:origin: spring-projects/spring-framework
@Override
public Instant convert(OffsetDateTime source) {
return source.toInstant();
}
}
代码示例来源:origin: org.springframework/spring-context
@Override
public Instant convert(OffsetDateTime source) {
return source.toInstant();
}
}
代码示例来源:origin: prestodb/presto
protected OffsetDateTimeSerializer() {
super(OffsetDateTime.class, dt -> dt.toInstant().toEpochMilli(),
OffsetDateTime::toEpochSecond, OffsetDateTime::getNano,
DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}
代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-jsr310
protected OffsetDateTimeSerializer() {
super(OffsetDateTime.class, dt -> dt.toInstant().toEpochMilli(),
OffsetDateTime::toEpochSecond, OffsetDateTime::getNano,
DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}
代码示例来源: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
*/
public static Date parseDateTime(String s) {
return Date.from(parseOffsetDateTime(s).toInstant());
}
代码示例来源:origin: requery/requery
@Override
public Timestamp convertToPersisted(OffsetDateTime value) {
if (value == null) {
return null;
}
Instant instant = value.toInstant();
return Timestamp.from(instant);
}
代码示例来源:origin: dropwizard/dropwizard
@Override
public void apply(final int position,
final PreparedStatement statement,
final StatementContext ctx) throws SQLException {
if (value != null) {
if (calendar.isPresent()) {
// We need to make a clone, because Calendar is not thread-safe
// and some JDBC drivers mutate it during time calculations
final Calendar calendarClone = (Calendar) calendar.get().clone();
statement.setTimestamp(position, Timestamp.from(value.toInstant()), calendarClone);
} else {
statement.setTimestamp(position, Timestamp.from(value.toInstant()));
}
} else {
statement.setNull(position, Types.TIMESTAMP);
}
}
}
代码示例来源: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: SonarSource/sonarqube
private void setCreatedAfterFromDates(IssueQuery.Builder builder, @Nullable Date createdAfter, @Nullable String createdInLast, boolean createdAfterInclusive) {
checkArgument(createdAfter == null || createdInLast == null, format("Parameters %s and %s cannot be set simultaneously", PARAM_CREATED_AFTER, PARAM_CREATED_IN_LAST));
Date actualCreatedAfter = createdAfter;
if (createdInLast != null) {
actualCreatedAfter = Date.from(
OffsetDateTime.now(clock)
.minus(Period.parse("P" + createdInLast.toUpperCase(Locale.ENGLISH)))
.toInstant());
}
builder.createdAfter(actualCreatedAfter, createdAfterInclusive);
}
代码示例来源:origin: embulk/embulk
@Override
Instant parseInternal(final String text) throws TimestampParseException {
final TemporalAccessor temporal;
try {
temporal = this.formatter.parse(text);
} catch (DateTimeParseException ex) {
throw new TimestampParseException(ex);
}
return this.buildOffsetDateTime(temporal).toInstant();
}
代码示例来源:origin: jdbi/jdbi
JavaTimeArgumentFactory() {
register(Instant.class, Types.TIMESTAMP, (p, i, v) -> p.setTimestamp(i, Timestamp.from(v)));
register(LocalDate.class, Types.DATE, (p, i, v) -> p.setDate(i, java.sql.Date.valueOf(v)));
register(LocalTime.class, Types.TIME, (p, i, v) -> p.setTime(i, Time.valueOf(v)));
register(LocalDateTime.class, Types.TIMESTAMP, (p, i, v) -> p.setTimestamp(i, Timestamp.valueOf(v)));
register(OffsetDateTime.class, Types.TIMESTAMP, (p, i, v) -> p.setTimestamp(i, Timestamp.from(v.toInstant())));
register(ZonedDateTime.class, Types.TIMESTAMP, (p, i, v) -> p.setTimestamp(i, Timestamp.from(v.toInstant())));
}
}
代码示例来源:origin: prestodb/presto
private static long millisUtc(OffsetTime offsetTime)
{
return offsetTime.atDate(LocalDate.ofEpochDay(0)).toInstant().toEpochMilli();
}
代码示例来源:origin: neo4j/neo4j
public Clock at( OffsetDateTime datetime )
{
return fixed( datetime.toInstant(), datetime.getOffset() );
}
代码示例来源: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());
}
代码示例来源:origin: embulk/embulk
@Test
public void testLegacy() {
testLegacyToFormat(OffsetDateTime.of(2017, 2, 28, 2, 0, 45, 0, ZoneOffset.UTC).toInstant(),
"%Y-%m-%dT%H:%M:%S %Z",
"Asia/Tokyo",
"2017-02-28T11:00:45 JST");
}
代码示例来源:origin: embulk/embulk
@Test
public void testJava() {
testJavaToFormat(OffsetDateTime.of(2017, 2, 28, 2, 0, 45, 0, ZoneOffset.UTC).toInstant(),
"EEE MMM dd HH:mm:ss uuuu XXXXX",
"-07:00",
"Mon Feb 27 19:00:45 2017 -07:00");
}
代码示例来源:origin: embulk/embulk
@Test
public void testRuby() {
testRubyToFormat(OffsetDateTime.of(2017, 2, 28, 2, 0, 45, 0, ZoneOffset.UTC).toInstant(),
"%Y-%m-%dT%H:%M:%S %Z",
"-09:00",
"2017-02-27T17:00:45 -09:00");
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void testSimpleDateTime() {
MapSettings settings = new MapSettings();
settings.appendProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01T12:13:14+0200");
settings.appendProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "version");
Clock clock = mock(Clock.class);
ProjectAnalysisInfo info = new ProjectAnalysisInfo(settings.asConfig(), clock);
info.start();
OffsetDateTime date = OffsetDateTime.of(2017, 1, 1, 12, 13, 14, 0, ZoneOffset.ofHours(2));
assertThat(info.analysisDate()).isEqualTo(Date.from(date.toInstant()));
assertThat(info.analysisVersion()).isEqualTo("version");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void shouldInsertCreatedAndModifiedFields() {
Person input = new Person("John", "Phiri");
input.setId(1);
recordNextTimestamp("now");
personDAO.insert(input);
assertThat(insertedTimestamp.getOffset()).isEqualTo(GMT_PLUS_2);
assertThat(insertedTimestamp.toInstant()).isEqualTo(UTC_MOMENT.toInstant());
Person result = personDAO.get(1);
assertThat(result.getCreated())
.isEqualTo(result.getModified())
.isEqualTo(insertedSqlTimestamp);
}
内容来源于网络,如有侵权,请联系作者删除!