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

x33g5p2x  于2022-01-23 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(381)

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

LocalDateTime.toEpochSecond介绍

暂无

代码示例

代码示例来源:origin: neo4j/neo4j

private LocalDateTimeValue( LocalDateTime value )
{
  this.value = value;
  this.epochSecondsInUTC = this.value.toEpochSecond(UTC);
}

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

public long toEpochSecond() {
 return localDateTime.toEpochSecond(ZoneOffset.UTC);
}

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

public long toEpochSecond() {
 return localDate.atStartOfDay().toEpochSecond(ZoneOffset.UTC);
}

代码示例来源:origin: blynkkk/blynk-server

public long getTime() {
  ZoneId zone;
  if (tzName != null) {
    zone = tzName;
  } else {
    zone = DateTimeUtils.UTC;
  }
  LocalDateTime ldt = LocalDateTime.now(zone);
  return ldt.toEpochSecond(ZoneOffset.UTC);
}

代码示例来源:origin: neo4j/neo4j

@Override
public void writeLocalDateTime( LocalDateTime localDateTime )
{
  buf.putLong( localDateTime.toEpochSecond( UTC ) );
  buf.putInt( localDateTime.getNano() );
}

代码示例来源:origin: neo4j/neo4j

private Instant nextInstantRaw()
{
  return Instant.ofEpochSecond(
      longBetween( LocalDateTime.MIN.toEpochSecond( UTC ), LocalDateTime.MAX.toEpochSecond( UTC ) ), nextLong( NANOS_PER_SECOND ) );
}

代码示例来源:origin: embulk/embulk

private static Timestamp createTimestampFromString(final String string) {
  // TODO: Handle exceptions.
  final Matcher matcher = TIMESTAMP_PATTERN.matcher(string);
  if (!matcher.matches()) {
    throw new IllegalArgumentException(String.format("Invalid timestamp format '%s'", string));
  }
  final long epochSecond = LocalDateTime.parse(matcher.group(1), FORMATTER).toEpochSecond(ZoneOffset.UTC);
  final String fraction = matcher.group(2);
  final int nanoAdjustment;
  if (fraction == null) {
    nanoAdjustment = 0;
  } else {
    nanoAdjustment = Integer.parseInt(fraction) * (int) Math.pow(10, 9 - fraction.length());
  }
  return Timestamp.ofEpochSecond(epochSecond, nanoAdjustment);
}

代码示例来源:origin: neo4j/neo4j

@Override
public final void writeLocalDateTime( LocalDateTime localDateTime ) throws E
{
  long epochSecond = localDateTime.toEpochSecond( UTC );
  int nano = localDateTime.getNano();
  writeLocalDateTime( epochSecond, nano );
}

代码示例来源:origin: neo4j/neo4j

@Override
  public void write( Object value, FlushableChannel into ) throws IOException
  {
    LocalDateTime ldt = (LocalDateTime) value;
    into.putLong( ldt.toEpochSecond( UTC) );
    into.putInt( ldt.getNano() );
  }
} );

代码示例来源:origin: neo4j/neo4j

public static byte[] encodeLocalDateTimeArray( LocalDateTime[] dateTimes )
{
  long[] data = new long[dateTimes.length * BLOCKS_LOCAL_DATETIME];
  for ( int i = 0; i < dateTimes.length; i++ )
  {
    data[i * BLOCKS_LOCAL_DATETIME] = dateTimes[i].toEpochSecond( UTC );
    data[i * BLOCKS_LOCAL_DATETIME + 1] = dateTimes[i].getNano();
  }
  TemporalHeader header = new TemporalHeader( TemporalType.TEMPORAL_LOCAL_DATE_TIME.temporalType );
  byte[] bytes = DynamicArrayStore.encodeFromNumbers( data, DynamicArrayStore.TEMPORAL_HEADER_SIZE );
  header.writeArrayHeaderTo( bytes );
  return bytes;
}

代码示例来源:origin: neo4j/neo4j

@Override
public void writeLocalDateTime( LocalDateTime localDateTime ) throws IOException
{
  long epochSecond = localDateTime.toEpochSecond( UTC );
  int nano = localDateTime.getNano();
  packStructHeader( LOCAL_DATE_TIME_SIZE, LOCAL_DATE_TIME );
  pack( epochSecond );
  pack( nano );
}

代码示例来源:origin: jtablesaw/tablesaw

/**
 * Returns the seconds from epoch for each value as an array based on the given offset
 *
 * If a value is missing, Long.MIN_VALUE is used
 */
public long[] asEpochSecondArray(ZoneOffset offset) {
  long[] output = new long[data.size()];
  for (int i = 0; i < data.size(); i++) {
    LocalDateTime dateTime = PackedLocalDateTime.asLocalDateTime(data.getLong(i));
    if (dateTime == null) {
      output[i] = Long.MIN_VALUE;
    } else {
      output[i] = dateTime.toEpochSecond(offset);
    }
  }
  return output;
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldPackLocalDateTimeWithTimeZoneId()
{
  LocalDateTime localDateTime = LocalDateTime.of( 1999, 12, 30, 9, 49, 20, 999999999 );
  ZoneId zoneId = ZoneId.of( "Europe/Stockholm" );
  ZonedDateTime zonedDateTime = ZonedDateTime.of( localDateTime, zoneId );
  PackedOutputArray packedOutput = pack( datetime( zonedDateTime ) );
  ByteBuffer buffer = ByteBuffer.wrap( packedOutput.bytes() );
  buffer.getShort(); // skip struct header
  assertEquals( INT_32, buffer.get() );
  assertEquals( localDateTime.toEpochSecond( UTC ), buffer.getInt() );
  assertEquals( INT_32, buffer.get() );
  assertEquals( localDateTime.getNano(), buffer.getInt() );
  buffer.getShort(); // skip zoneId string header
  byte[] zoneIdBytes = new byte[zoneId.getId().getBytes( UTF_8 ).length];
  buffer.get( zoneIdBytes );
  assertEquals( zoneId.getId(), new String( zoneIdBytes, UTF_8 ) );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldPackLocalDateTimeWithTimeZoneOffset()
{
  LocalDateTime localDateTime = LocalDateTime.of( 2015, 3, 23, 19, 15, 59, 10 );
  ZoneOffset offset = ZoneOffset.ofHoursMinutes( -5, -15 );
  ZonedDateTime zonedDateTime = ZonedDateTime.of( localDateTime, offset );
  PackedOutputArray packedOutput = pack( datetime( zonedDateTime ) );
  ByteBuffer buffer = ByteBuffer.wrap( packedOutput.bytes() );
  buffer.getShort(); // skip struct header
  assertEquals( INT_32, buffer.get() );
  assertEquals( localDateTime.toEpochSecond( UTC ), buffer.getInt() );
  assertEquals( localDateTime.getNano(), buffer.get() );
  assertEquals( INT_16, buffer.get() );
  assertEquals( offset.getTotalSeconds(), buffer.getShort() );
}

代码示例来源:origin: Netflix/conductor

@Test
public void taskExecutionLogs() throws Exception {
  TaskExecLog taskExecLog1 = new TaskExecLog();
  taskExecLog1.setTaskId("some-task-id");
  long createdTime1 = LocalDateTime.of(2018, 11, 01, 06, 33, 22)
      .toEpochSecond(ZoneOffset.UTC);
  taskExecLog1.setCreatedTime(createdTime1);
  taskExecLog1.setLog("some-log");
  TaskExecLog taskExecLog2 = new TaskExecLog();
  taskExecLog2.setTaskId("some-task-id");
  long createdTime2 = LocalDateTime.of(2018, 11, 01, 06, 33, 22)
      .toEpochSecond(ZoneOffset.UTC);
  taskExecLog2.setCreatedTime(createdTime2);
  taskExecLog2.setLog("some-log");
  List<TaskExecLog> logsToAdd = Arrays.asList(taskExecLog1, taskExecLog2);
  indexDAO.addTaskExecutionLogs(logsToAdd);
  await()
      .atMost(5, TimeUnit.SECONDS)
      .untilAsserted(() -> {
        List<TaskExecLog> taskExecutionLogs = indexDAO.getTaskExecutionLogs("some-task-id");
        assertEquals(2, taskExecutionLogs.size());
      });
}

代码示例来源:origin: Netflix/conductor

@Test
public void taskExecutionLogs() throws Exception {
  TaskExecLog taskExecLog1 = new TaskExecLog();
  taskExecLog1.setTaskId("some-task-id");
  long createdTime1 = LocalDateTime.of(2018, 11, 01, 06, 33, 22)
      .toEpochSecond(ZoneOffset.UTC);
  taskExecLog1.setCreatedTime(createdTime1);
  taskExecLog1.setLog("some-log");
  TaskExecLog taskExecLog2 = new TaskExecLog();
  taskExecLog2.setTaskId("some-task-id");
  long createdTime2 = LocalDateTime.of(2018, 11, 01, 06, 33, 22)
      .toEpochSecond(ZoneOffset.UTC);
  taskExecLog2.setCreatedTime(createdTime2);
  taskExecLog2.setLog("some-log");
  List<TaskExecLog> logsToAdd = Arrays.asList(taskExecLog1, taskExecLog2);
  indexDAO.addTaskExecutionLogs(logsToAdd);
  await()
      .atMost(5, TimeUnit.SECONDS)
      .untilAsserted(() -> {
        List<TaskExecLog> taskExecutionLogs = indexDAO.getTaskExecutionLogs("some-task-id");
        assertEquals(2, taskExecutionLogs.size());
      });
}

代码示例来源:origin: neo4j/neo4j

@Override
  public void writeDateTime( ZonedDateTime zonedDateTime ) throws IOException
  {
    long epochSecondLocal = zonedDateTime.toLocalDateTime().toEpochSecond( UTC );
    int nano = zonedDateTime.getNano();
    ZoneId zone = zonedDateTime.getZone();
    if ( zone instanceof ZoneOffset )
    {
      int offsetSeconds = ((ZoneOffset) zone).getTotalSeconds();
      packStructHeader( DATE_TIME_WITH_ZONE_OFFSET_SIZE, DATE_TIME_WITH_ZONE_OFFSET );
      pack( epochSecondLocal );
      pack( nano );
      pack( offsetSeconds );
    }
    else
    {
      String zoneId = zone.getId();
      packStructHeader( DATE_TIME_WITH_ZONE_NAME_SIZE, DATE_TIME_WITH_ZONE_NAME );
      pack( epochSecondLocal );
      pack( nano );
      pack( zoneId );
    }
  }
}

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

@SuppressWarnings("unchecked")
 private void setTimestamp(JSONObject message) throws ParseException {
  String timeStampString = (String) message.get(SyslogFieldKeys.HEADER_TIMESTAMP.getField());
  if (!StringUtils.isBlank(timeStampString) && !timeStampString.equals("-")) {
   message.put("timestamp", SyslogUtils.parseTimestampToEpochMillis(timeStampString, deviceClock));
  } else {
   message.put(
     "timestamp",
     LocalDateTime.now()
       .toEpochSecond(ZoneOffset.UTC));
  }
 }
}

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

/**
 * Gets the transition instant as an epoch second.
 *
 * @return the transition epoch second
 */
public long toEpochSecond() {
  return transition.toEpochSecond(offsetBefore);
}

代码示例来源:origin: org.neo4j/neo4j-kernel

@Override
  public void write( Object value, FlushableChannel into ) throws IOException
  {
    LocalDateTime ldt = (LocalDateTime) value;
    into.putLong( ldt.toEpochSecond( UTC) );
    into.putInt( ldt.getNano() );
  }
} );

相关文章

LocalDateTime类方法