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

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

本文整理了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

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

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

  1. private static EventDateTime getEventDateTime(CalendarEventModel.CalendarEventTime dateTime) {
  2. if (dateTime == null) {
  3. return null;
  4. }
  5. EventDateTime eventDateTime = new EventDateTime();
  6. // google's APIs want millisecond from epoch, and the timezone offset in minutes.
  7. if (dateTime.isDateOnly()) {
  8. eventDateTime.setDate(new DateTime(true,
  9. dateTime.getDateTime().toEpochSecond() * 1000,
  10. dateTime.getDateTime().getOffset().getTotalSeconds() / 60));
  11. } else {
  12. eventDateTime.setDateTime(new DateTime(
  13. dateTime.getDateTime().toEpochSecond() * 1000,
  14. dateTime.getDateTime().getOffset().getTotalSeconds() / 60));
  15. }
  16. return eventDateTime;
  17. }

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

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

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

  1. /**
  2. * Simple test JMX bean for caches IO stats.
  3. *
  4. * @throws Exception In case of failure.
  5. */
  6. @Test
  7. public void testCacheBasic() throws Exception {
  8. IoStatisticsMetricsMXBean bean = ioStatMXBean();
  9. IoStatisticsManager ioStatMgr = ignite.context().ioStats();
  10. Assert.assertEquals(ioStatMgr.startTime().toEpochSecond(), bean.getStartTime());
  11. Assert.assertEquals(ioStatMgr.startTime().format(DateTimeFormatter.ISO_DATE_TIME), bean.getStartTimeLocal());
  12. bean.reset();
  13. Assert.assertEquals(ioStatMgr.startTime().toEpochSecond(), bean.getStartTime());
  14. Assert.assertEquals(ioStatMgr.startTime().format(DateTimeFormatter.ISO_DATE_TIME), bean.getStartTimeLocal());
  15. int cnt = 100;
  16. warmUpMemmory(bean, cnt);
  17. populateCache(cnt);
  18. Long cacheLogicalReadsCnt = bean.getCacheGroupLogicalReads(DEFAULT_CACHE_NAME);
  19. Assert.assertNotNull(cacheLogicalReadsCnt);
  20. Assert.assertEquals(cnt, cacheLogicalReadsCnt.longValue());
  21. Long cachePhysicalReadsCnt = bean.getCacheGroupPhysicalReads(DEFAULT_CACHE_NAME);
  22. Assert.assertNotNull(cachePhysicalReadsCnt);
  23. Assert.assertEquals(0, cachePhysicalReadsCnt.longValue());
  24. String formatted = bean.getCacheGroupStatistics(DEFAULT_CACHE_NAME);
  25. Assert.assertEquals("CACHE_GROUP default [LOGICAL_READS=100, PHYSICAL_READS=0]", formatted);
  26. String unexistedStats = bean.getCacheGroupStatistics("unknownCache");
  27. Assert.assertEquals("CACHE_GROUP unknownCache []", unexistedStats);
  28. }

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

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

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

  1. @Override
  2. public Timestamp toNonNullValue(OffsetDateTime value) {
  3. final Timestamp timestamp = new Timestamp((value.toEpochSecond() * MILLIS_IN_SECOND));
  4. timestamp.setNanos(value.getNano());
  5. return timestamp;
  6. }

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

  1. @Override
  2. public Timestamp toNonNullValue(OffsetDateTime value) {
  3. final Timestamp timestamp = new Timestamp((value.toEpochSecond() * MILLIS_IN_SECOND));
  4. timestamp.setNanos(value.getNano());
  5. return timestamp;
  6. }

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

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

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

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

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

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

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

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

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

  1. /**
  2. * Converts the given OffsetDateTime to a Timestamp.
  3. *
  4. * @param offsetDateTime
  5. * the OffsetDateTime to convert
  6. * @return Timestamp object that is equivalent to the given OffsetDateTime.
  7. */
  8. private static Timestamp toTimestamp(OffsetDateTime offsetDateTime) {
  9. long seconds = offsetDateTime.toEpochSecond();
  10. int nanos = offsetDateTime.getNano();
  11. long microseconds = TimeUnit.SECONDS.toMicros(seconds) + TimeUnit.NANOSECONDS.toMicros(nanos);
  12. return Timestamp.ofTimeMicroseconds(microseconds);
  13. }

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

  1. @Override
  2. public int compare(OffsetDateTime datetime1, OffsetDateTime datetime2) {
  3. int cmp = Jdk8Methods.compareLongs(datetime1.toEpochSecond(), datetime2.toEpochSecond());
  4. if (cmp == 0) {
  5. cmp = Jdk8Methods.compareLongs(datetime1.getNano(), datetime2.getNano());
  6. }
  7. return cmp;
  8. }
  9. };

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

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

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

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

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

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

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

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

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

  1. @Override
  2. public ValueBuilder<?, ?, ?> toDatastore(Object input) {
  3. if (input == null) {
  4. return NullValue.newBuilder();
  5. }
  6. OffsetDateTime offsetDateTime = (OffsetDateTime) input;
  7. long seconds = offsetDateTime.toEpochSecond();
  8. int nanos = offsetDateTime.getNano();
  9. long microseconds = TimeUnit.SECONDS.toMicros(seconds) + TimeUnit.NANOSECONDS.toMicros(nanos);
  10. return TimestampValue.newBuilder(Timestamp.ofTimeMicroseconds(microseconds));
  11. }

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

  1. @Test
  2. public void get() throws SQLException {
  3. ResultSet resultSet = EasyMock.createNiceMock(ResultSet.class);
  4. EasyMock.expect(resultSet.getTimestamp(1, UTC)).andReturn(new Timestamp(UTC.getTimeInMillis()));
  5. EasyMock.replay(resultSet);
  6. OffsetDateTime result = type.getValue(resultSet, 1);
  7. EasyMock.verify(resultSet);
  8. assertNotNull(result);
  9. assertTrue(result.toEpochSecond() == 0);
  10. }
  11. }

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

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

相关文章