java.time.OffsetDateTime.toEpochSecond()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(170)

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

OffsetDateTime.toEpochSecond介绍

[英]Converts this date-time to the number of seconds from the epoch of 1970-01-01T00:00:00Z.

This allows this date-time to be converted to a value of the ChronoField#INSTANT_SECONDS field. This is primarily intended for low-level conversions rather than general application usage.
[中]将此日期时间转换为从1970-01-01T00:00:00Z开始的秒数。
这允许将此日期时间转换为ChronoField#INSTANT_SECONDS字段的值。这主要用于低级别转换,而不是一般的应用程序使用。

代码示例

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public long getStartTime() {
  return statMgr.startTime().toEpochSecond();
}

代码示例来源:origin: google/data-transfer-project

private static EventDateTime getEventDateTime(CalendarEventModel.CalendarEventTime dateTime) {
 if (dateTime == null) {
  return null;
 }
 EventDateTime eventDateTime = new EventDateTime();
 // google's APIs want millisecond from epoch, and the timezone offset in minutes.
 if (dateTime.isDateOnly()) {
  eventDateTime.setDate(new DateTime(true,
    dateTime.getDateTime().toEpochSecond() * 1000,
    dateTime.getDateTime().getOffset().getTotalSeconds() / 60));
 } else {
  eventDateTime.setDateTime(new DateTime(
    dateTime.getDateTime().toEpochSecond() * 1000,
    dateTime.getDateTime().getOffset().getTotalSeconds() / 60));
 }
 return eventDateTime;
}

代码示例来源:origin: apache/ignite

Assert.assertEquals(ioStatMgr.startTime().toEpochSecond(), bean.getStartTime());
Assert.assertEquals(ioStatMgr.startTime().toEpochSecond(), bean.getStartTime());

代码示例来源:origin: apache/ignite

/**
 * Simple test JMX bean for caches IO stats.
 *
 * @throws Exception In case of failure.
 */
@Test
public void testCacheBasic() throws Exception {
  IoStatisticsMetricsMXBean bean = ioStatMXBean();
  IoStatisticsManager ioStatMgr = ignite.context().ioStats();
  Assert.assertEquals(ioStatMgr.startTime().toEpochSecond(), bean.getStartTime());
  Assert.assertEquals(ioStatMgr.startTime().format(DateTimeFormatter.ISO_DATE_TIME), bean.getStartTimeLocal());
  bean.reset();
  Assert.assertEquals(ioStatMgr.startTime().toEpochSecond(), bean.getStartTime());
  Assert.assertEquals(ioStatMgr.startTime().format(DateTimeFormatter.ISO_DATE_TIME), bean.getStartTimeLocal());
  int cnt = 100;
  warmUpMemmory(bean, cnt);
  populateCache(cnt);
  Long cacheLogicalReadsCnt = bean.getCacheGroupLogicalReads(DEFAULT_CACHE_NAME);
  Assert.assertNotNull(cacheLogicalReadsCnt);
  Assert.assertEquals(cnt, cacheLogicalReadsCnt.longValue());
  Long cachePhysicalReadsCnt = bean.getCacheGroupPhysicalReads(DEFAULT_CACHE_NAME);
  Assert.assertNotNull(cachePhysicalReadsCnt);
  Assert.assertEquals(0, cachePhysicalReadsCnt.longValue());
  String formatted = bean.getCacheGroupStatistics(DEFAULT_CACHE_NAME);
  Assert.assertEquals("CACHE_GROUP default [LOGICAL_READS=100, PHYSICAL_READS=0]", formatted);
  String unexistedStats = bean.getCacheGroupStatistics("unknownCache");
  Assert.assertEquals("CACHE_GROUP unknownCache []", unexistedStats);
}

代码示例来源:origin: ebean-orm/ebean

@Override
protected String toJsonNanos(OffsetDateTime value) {
 return toJsonNanos(value.toEpochSecond(), value.getNano());
}

代码示例来源:origin: org.jadira.usertype/usertype.extended

@Override
public Timestamp toNonNullValue(OffsetDateTime value) {
  
  final Timestamp timestamp = new Timestamp((value.toEpochSecond() * MILLIS_IN_SECOND));
  timestamp.setNanos(value.getNano());
  return timestamp;
}

代码示例来源:origin: org.jadira.usertype/usertype.core

@Override
public Timestamp toNonNullValue(OffsetDateTime value) {
  
  final Timestamp timestamp = new Timestamp((value.toEpochSecond() * MILLIS_IN_SECOND));
  timestamp.setNanos(value.getNano());
  return timestamp;
}

代码示例来源:origin: optimatika/ojAlgo

public static CalendarDate valueOf(OffsetDateTime offsetDateTime) {
  return new CalendarDate(offsetDateTime.toEpochSecond() * MILLIS_PER_SECOND);
}

代码示例来源:origin: org.ojalgo/ojalgo

public static CalendarDate valueOf(OffsetDateTime offsetDateTime) {
  return new CalendarDate(offsetDateTime.toEpochSecond() * MILLIS_PER_SECOND);
}

代码示例来源:origin: org.jadira.usertype/usertype.core

@Override
public Timestamp toNonNullValue(OffsetTime value) {
  OffsetDateTime odt = value.atDate(LocalDate.of(1970, 1, 1));
  
  final Timestamp timestamp = new Timestamp((odt.toEpochSecond() * MILLIS_IN_SECOND));
  timestamp.setNanos(value.getNano());
  return timestamp;
}

代码示例来源:origin: org.jadira.usertype/usertype.extended

@Override
public Timestamp toNonNullValue(OffsetTime value) {
  OffsetDateTime odt = value.atDate(LocalDate.of(1970, 1, 1));
  
  final Timestamp timestamp = new Timestamp((odt.toEpochSecond() * MILLIS_IN_SECOND));
  timestamp.setNanos(value.getNano());
  return timestamp;
}

代码示例来源:origin: sai-pullabhotla/catatumbo

/**
 * Converts the given OffsetDateTime to a Timestamp.
 * 
 * @param offsetDateTime
 *          the OffsetDateTime to convert
 * @return Timestamp object that is equivalent to the given OffsetDateTime.
 */
private static Timestamp toTimestamp(OffsetDateTime offsetDateTime) {
 long seconds = offsetDateTime.toEpochSecond();
 int nanos = offsetDateTime.getNano();
 long microseconds = TimeUnit.SECONDS.toMicros(seconds) + TimeUnit.NANOSECONDS.toMicros(nanos);
 return Timestamp.ofTimeMicroseconds(microseconds);
}

代码示例来源:origin: com.github.seratch/java-time-backport

@Override
  public int compare(OffsetDateTime datetime1, OffsetDateTime datetime2) {
    int cmp = Jdk8Methods.compareLongs(datetime1.toEpochSecond(), datetime2.toEpochSecond());
    if (cmp == 0) {
      cmp = Jdk8Methods.compareLongs(datetime1.getNano(), datetime2.getNano());
    }
    return cmp;
  }
};

代码示例来源:origin: io.ebean/ebean

@Override
protected String toJsonNanos(OffsetDateTime value) {
 return toJsonNanos(value.toEpochSecond(), value.getNano());
}

代码示例来源:origin: org.avaje.ebean/ebean

@Override
protected String toJsonNanos(OffsetDateTime value) {
 return toJsonNanos(value.toEpochSecond(), value.getNano());
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * Checks if the instant of this date-time is after that of the specified date-time.
 * <p>
 * This method differs from the comparison in {@link #compareTo} and {@link #equals} in that it
 * only compares the instant of the date-time. This is equivalent to using
 * {@code dateTime1.toInstant().isAfter(dateTime2.toInstant());}.
 *
 * @param other  the other date-time to compare to, not null
 * @return true if this is after the instant of the specified date-time
 */
public boolean isAfter(OffsetDateTime other) {
  long thisEpochSec = toEpochSecond();
  long otherEpochSec = other.toEpochSecond();
  return thisEpochSec > otherEpochSec ||
    (thisEpochSec == otherEpochSec && toLocalTime().getNano() > other.toLocalTime().getNano());
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * Checks if the instant of this date-time is equal to that of the specified date-time.
 * <p>
 * This method differs from the comparison in {@link #compareTo} and {@link #equals}
 * in that it only compares the instant of the date-time. This is equivalent to using
 * {@code dateTime1.toInstant().equals(dateTime2.toInstant());}.
 *
 * @param other  the other date-time to compare to, not null
 * @return true if the instant equals the instant of the specified date-time
 */
public boolean isEqual(OffsetDateTime other) {
  return toEpochSecond() == other.toEpochSecond() &&
      toLocalTime().getNano() == other.toLocalTime().getNano();
}

代码示例来源:origin: sai-pullabhotla/catatumbo

@Override
public ValueBuilder<?, ?, ?> toDatastore(Object input) {
 if (input == null) {
  return NullValue.newBuilder();
 }
 OffsetDateTime offsetDateTime = (OffsetDateTime) input;
 long seconds = offsetDateTime.toEpochSecond();
 int nanos = offsetDateTime.getNano();
 long microseconds = TimeUnit.SECONDS.toMicros(seconds) + TimeUnit.NANOSECONDS.toMicros(nanos);
 return TimestampValue.newBuilder(Timestamp.ofTimeMicroseconds(microseconds));
}

代码示例来源:origin: com.querydsl/querydsl-sql

@Test
  public void get() throws SQLException {
    ResultSet resultSet = EasyMock.createNiceMock(ResultSet.class);
    EasyMock.expect(resultSet.getTimestamp(1, UTC)).andReturn(new Timestamp(UTC.getTimeInMillis()));
    EasyMock.replay(resultSet);

    OffsetDateTime result = type.getValue(resultSet, 1);
    EasyMock.verify(resultSet);

    assertNotNull(result);
    assertTrue(result.toEpochSecond() == 0);
  }
}

代码示例来源:origin: kiegroup/optaweb-employee-rostering

public static LocalDateTime toLocalDateTimeInZone(OffsetDateTime dateTime, ZoneId zoneId) {
  return LocalDateTime.ofEpochSecond(dateTime.toEpochSecond(), dateTime.getNano(),
                    zoneId.getRules().getOffset(dateTime.toInstant()));
}

相关文章