本文整理了Java中java.time.LocalDateTime.ofEpochSecond()
方法的一些代码示例,展示了LocalDateTime.ofEpochSecond()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.ofEpochSecond()
方法的具体详情如下:
包路径:java.time.LocalDateTime
类名称:LocalDateTime
方法名:ofEpochSecond
[英]Obtains an instance of LocalDateTime using seconds from the epoch of 1970-01-01T00:00:00Z.
This allows the ChronoField#INSTANT_SECONDS field to be converted to a local date-time. This is primarily intended for low-level conversions rather than general application usage.
[中]从1970-01-01T00:00:00Z的纪元开始,使用秒获取LocalDateTime的实例。
这允许将ChronoField#INSTANT_SECONDS字段转换为本地日期时间。这主要用于低级转换,而不是一般的应用程序使用。
代码示例来源:origin: apache/hive
public void setTimeInSeconds(long epochSecond, int nanos) {
localDateTime = LocalDateTime.ofEpochSecond(
epochSecond, nanos, ZoneOffset.UTC);
}
代码示例来源:origin: debezium/debezium
/**
* Get the UTC-based {@link LocalDateTime} for given microseconds epoch
*
* @param microseconds - timestamp in microseconds
* @return timestamp in UTC timezone
*/
public static LocalDateTime toLocalDateTimeUTC(long microseconds) {
long seconds = microseconds / MICROSECONDS_PER_SECOND;
// typecasting is safe as microseconds and nanoseconds in second fit in int range
int microsecondsOfSecond = (int)(microseconds % MICROSECONDS_PER_SECOND);
if (microsecondsOfSecond < 0) {
seconds--;
microsecondsOfSecond = (int)Conversions.MICROSECONDS_PER_SECOND + microsecondsOfSecond;
}
return LocalDateTime.ofEpochSecond(seconds, (int)(microsecondsOfSecond * NANOSECONDS_PER_MICROSECOND), ZoneOffset.UTC);
}
代码示例来源:origin: debezium/debezium
/**
* Get the UTC-based {@link LocalDateTime} for given nanoseconds epoch
*
* @param nanoseconds - timestamp in nanoseconds
* @return timestamp in UTC timezone
*/
public static LocalDateTime fromNanosToLocalDateTimeUTC(long nanoseconds) {
long seconds = nanoseconds / NANOSECONDS_PER_SECOND;
// typecasting is safe as microseconds and nanoseconds in second fit in int range
int nanosecondsOfSecond = (int)(nanoseconds % NANOSECONDS_PER_SECOND);
if (nanosecondsOfSecond < 0) {
seconds--;
nanosecondsOfSecond = (int)Conversions.NANOSECONDS_PER_SECOND + nanosecondsOfSecond;
}
return LocalDateTime.ofEpochSecond(seconds, nanosecondsOfSecond, ZoneOffset.UTC);
}
代码示例来源:origin: neo4j/neo4j
private static ArrayValue readLocalDateTimeArray( ByteBuffer bb, int offset )
{
final int len = bb.getInt( offset );
offset += Integer.BYTES;
final LocalDateTime[] array = new LocalDateTime[len];
for ( int i = 0; i < len; i++ )
{
final long epochSecond = bb.getLong( offset );
offset += Long.BYTES;
final int nanos = bb.getInt( offset );
offset += Integer.BYTES;
array[i] = LocalDateTime.ofEpochSecond( epochSecond, nanos, UTC );
}
return localDateTimeArray( array );
}
代码示例来源:origin: apache/hive
/**
* Compute the expired date partition, using the underlying clock in UTC time.
*/
private static void computeExpiredDatePtn(long ttl) {
// Use UTC date to ensure reader date is same on all timezones.
LocalDate expiredDate
= LocalDateTime.ofEpochSecond((clock.getTime() - ttl) / 1000, 0, ZoneOffset.UTC).toLocalDate();
expiredDatePtn = "date=" + DateTimeFormatter.ISO_LOCAL_DATE.format(expiredDate);
}
代码示例来源:origin: apache/hive
/**
* Returns the current time, using the underlying clock in UTC time.
*/
public LocalDateTime getNow() {
// Use UTC date to ensure reader date is same on all timezones.
return LocalDateTime.ofEpochSecond(clock.getTime() / 1000, 0, ZoneOffset.UTC);
}
代码示例来源:origin: apache/hive
public static Timestamp ofEpochSecond(long epochSecond, int nanos) {
return new Timestamp(
LocalDateTime.ofEpochSecond(epochSecond, nanos, ZoneOffset.UTC));
}
代码示例来源:origin: neo4j/neo4j
@Override
public Object read( ReadableClosableChannel from ) throws IOException
{
return LocalDateTime.ofEpochSecond( from.getLong(), from.getInt(), UTC );
}
代码示例来源:origin: org.postgresql/postgresql
/**
* Returns the local date time object matching the given bytes with {@link Oid#TIMESTAMP} or
* {@link Oid#TIMESTAMPTZ}.
*
* @param tz time zone to use
* @param bytes The binary encoded local date time value.
* @return The parsed local date time object.
* @throws PSQLException If binary format could not be parsed.
*/
public LocalDateTime toLocalDateTimeBin(TimeZone tz, byte[] bytes) throws PSQLException {
ParsedBinaryTimestamp parsedTimestamp = this.toParsedTimestampBin(tz, bytes, true);
if (parsedTimestamp.infinity == Infinity.POSITIVE) {
return LocalDateTime.MAX;
} else if (parsedTimestamp.infinity == Infinity.NEGATIVE) {
return LocalDateTime.MIN;
}
return LocalDateTime.ofEpochSecond(parsedTimestamp.millis / 1000L, parsedTimestamp.nanos, ZoneOffset.UTC);
}
//JCP! endif
代码示例来源:origin: yu199195/Raincat
/**
* 将当前时区时间转成UTC时间.
*
* @param dateTime 时间
* @return LocalDateTime
*/
public static LocalDateTime toUTCDateTime(final LocalDateTime dateTime) {
if (dateTime == null) {
return null;
} else {
Instant instant = dateTime.toInstant(DEFAULT_ZONE.getRules().getOffset(dateTime));
return LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), ZoneOffset.UTC);
}
}
代码示例来源:origin: debezium/debezium
protected Object convertTimestampWithZone(Column column, Field fieldDefn, Object data) {
if (!(data instanceof DateTimeOffset)) {
return super.convertTimestampWithZone(column, fieldDefn, data);
}
final DateTimeOffset dto = (DateTimeOffset)data;
// Timestamp is provided in UTC time
final Timestamp utc = dto.getTimestamp();
final ZoneOffset offset = ZoneOffset.ofTotalSeconds(dto.getMinutesOffset() * 60);
return super.convertTimestampWithZone(column, fieldDefn, LocalDateTime.ofEpochSecond(utc.getTime() / 1000, utc.getNanos(), offset).atOffset(offset));
}
代码示例来源:origin: prestodb/presto
if (DATE.equals(originalType)) {
SqlDate date = (SqlDate) originalType.getObjectValue(connectorSession, block, position);
LocalDateTime ldt = LocalDateTime.ofEpochSecond(TimeUnit.DAYS.toSeconds(date.getDays()), 0, ZoneOffset.UTC);
byte[] bytes = ldt.format(DateTimeFormatter.ISO_LOCAL_DATE).getBytes(StandardCharsets.UTF_8);
row.addStringUtf8(destChannel, bytes);
代码示例来源:origin: awslabs/aws-serverless-java-container
dateFormat.format(
ZonedDateTime.of(
LocalDateTime.ofEpochSecond(gatewayContext.getRequestTimeEpoch() / 1000, 0, ZoneOffset.UTC),
ZoneId.systemDefault()
代码示例来源:origin: debezium/debezium
long c3Seconds = c3.getTime() / 1000;
long c3Millis = c3.getTime() % 1000;
LocalDateTime c3DateTime = LocalDateTime.ofEpochSecond(c3Seconds,
(int) TimeUnit.MILLISECONDS.toNanos(c3Millis),
ZoneOffset.UTC);
代码示例来源:origin: novoda/spikes
private static LocalDateTime convertToLocalDateTime(String lastResponseEpochTime) {
int decimalSplit = lastResponseEpochTime.indexOf(".");
Long epochSecond = Long.valueOf(lastResponseEpochTime.substring(0, decimalSplit));
Integer nanoOfSecond = Integer.valueOf(lastResponseEpochTime.substring(decimalSplit + 1));
ZoneOffset timezone = ZoneOffset.UTC;
return LocalDateTime.ofEpochSecond(epochSecond, nanoOfSecond, timezone);
}
}
代码示例来源:origin: novoda/spikes
private LocalDateTime convertToLocalDateTime(String lastResponseEpochTime) {
int decimalSplit = lastResponseEpochTime.indexOf(".");
Long epochSecond = Long.valueOf(lastResponseEpochTime.substring(0, decimalSplit));
Integer nanoOfSecond = Integer.valueOf(lastResponseEpochTime.substring(decimalSplit + 1));
ZoneOffset timezone = ZoneOffset.UTC;
return LocalDateTime.ofEpochSecond(epochSecond, nanoOfSecond, timezone);
}
代码示例来源:origin: jzyong/game-server
/**
* 获取一个带时间偏移量和时区的LocalDateTime
*
* @return
*/
public static LocalDateTime getLocalDateTime() {
long currentTimeMillis = currentTimeMillis();
return LocalDateTime.ofEpochSecond(currentTimeMillis / 1000, 0, ZONE_OFFSET);
}
代码示例来源:origin: jzyong/game-server
/**
* 获取一个带时间偏移量和时区的LocalDate
*
* @return
*/
public static LocalDate getLocalDate() {
long currentTimeMillis = currentTimeMillis();
LocalDateTime ldt = LocalDateTime.ofEpochSecond(currentTimeMillis / 1000, 0, ZONE_OFFSET);
return ldt.toLocalDate();
}
代码示例来源:origin: org.neo4j/neo4j-kernel
@Override
public Object read( ReadableClosableChannel from ) throws IOException
{
return LocalDateTime.ofEpochSecond( from.getLong(), from.getInt(), UTC );
}
代码示例来源:origin: org.neo4j.driver/neo4j-java-driver
private Value unpackLocalDateTime() throws IOException
{
long epochSecondUtc = unpacker.unpackLong();
int nano = Math.toIntExact( unpacker.unpackLong() );
return value( LocalDateTime.ofEpochSecond( epochSecondUtc, nano, UTC ) );
}
内容来源于网络,如有侵权,请联系作者删除!