本文整理了Java中java.time.ZoneOffset.ofTotalSeconds()
方法的一些代码示例,展示了ZoneOffset.ofTotalSeconds()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneOffset.ofTotalSeconds()
方法的具体详情如下:
包路径:java.time.ZoneOffset
类名称:ZoneOffset
方法名:ofTotalSeconds
[英]Obtains an instance of ZoneOffset specifying the total offset in seconds
The offset must be in the range -18:00 to +18:00, which corresponds to -64800 to +64800.
[中]获取ZoneOffset的实例,指定以秒为单位的总偏移量
偏移量必须在-18:00到+18:00的范围内,对应于-64800到+64800。
代码示例来源:origin: neo4j/neo4j
@Override
public Value decodeForTemporal( long[] valueBlocks, int offset )
{
int secondOffset = (int) (valueBlocks[offset] >>> 32);
long nanoOfDay = valueBlocks[1 + offset];
checkValidNanoOfDayWithOffset( nanoOfDay, secondOffset );
return TimeValue.time( nanoOfDay, ZoneOffset.ofTotalSeconds( secondOffset ) );
}
代码示例来源:origin: neo4j/neo4j
private static OffsetTime readRawTime( ByteBuffer bb, int offset )
{
final long nanosOfDayUTC = bb.getLong( offset );
offset += Long.BYTES;
final int offsetSeconds = bb.getInt( offset );
return OffsetTime.ofInstant( Instant.ofEpochSecond( 0, nanosOfDayUTC ), ZoneOffset.ofTotalSeconds( offsetSeconds ) );
}
代码示例来源:origin: neo4j/neo4j
private static ZoneId toZoneId( int z )
{
// if lowest bit is set to 1 then it's a shifted zone id
if ( (z & 1) != 0 )
{
final String zoneId = TimeZones.map( (short) (z >> 1) );
return ZoneId.of( zoneId );
}
// otherwise it's a shifted offset seconds value
// preserve sign bit for negative offsets
return ZoneOffset.ofTotalSeconds( z >> 1 );
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
@Override
public String toString(final Object obj) {
final Calendar calendar = (Calendar)obj;
final Instant instant = Instant.ofEpochMilli(calendar.getTimeInMillis());
final int offsetInMillis = calendar.getTimeZone().getOffset(calendar.getTimeInMillis());
final OffsetDateTime offsetDateTime = OffsetDateTime.ofInstant(instant, ZoneOffset.ofTotalSeconds(offsetInMillis
/ 1000));
return STD_DATE_TIME.format(offsetDateTime);
}
}
代码示例来源:origin: neo4j/neo4j
@Override
public Value asValue()
{
// We need to check validity upfront without throwing exceptions, because the PageCursor might give garbage bytes
if ( TimeZones.validZoneOffset( zoneOffsetSeconds ) )
{
return TimeValue.time( nanosOfDayUTC, ZoneOffset.ofTotalSeconds( zoneOffsetSeconds ) );
}
return NO_VALUE;
}
代码示例来源:origin: neo4j/neo4j
static OffsetTime asValueRaw( long long0, long long1 )
{
if ( TimeZones.validZoneOffset( (int) long1 ) )
{
return TimeValue.timeRaw( long0, ZoneOffset.ofTotalSeconds( (int) long1 ) );
}
// TODO Getting here means that after a proper read this value is plain wrong... shouldn't something be thrown instead? Yes and same for TimeZones
return null;
}
代码示例来源:origin: neo4j/neo4j
@Override
public Object read( ReadableClosableChannel from ) throws IOException
{
return OffsetTime.ofInstant( Instant.ofEpochSecond( 0, from.getLong() ), ZoneOffset.ofTotalSeconds( from.getInt() ) );
}
代码示例来源:origin: spring-cloud/spring-cloud-gateway
@Override
public ZonedDateTime convert(String source) {
ZonedDateTime dateTime;
try {
long epoch = Long.parseLong(source);
dateTime = Instant.ofEpochMilli(epoch).atOffset(ZoneOffset.ofTotalSeconds(0))
.toZonedDateTime();
} catch (NumberFormatException e) {
// try ZonedDateTime instead
dateTime = ZonedDateTime.parse(source);
}
return dateTime;
}
}
代码示例来源:origin: neo4j/neo4j
static ZonedDateTime asValueRaw( long long0, long long1, long long2, long long3 )
{
return TimeZones.validZoneId( (short) long2 ) ?
DateTimeValue.datetimeRaw( long0, long1, ZoneId.of( TimeZones.map( (short) long2 ) ) ) :
DateTimeValue.datetimeRaw( long0, long1, ZoneOffset.ofTotalSeconds( (int) long3 ) );
}
代码示例来源:origin: neo4j/neo4j
public static OffsetTime truncateOffsetToMinutes( OffsetTime value )
{
int offsetMinutes = value.getOffset().getTotalSeconds() / 60;
ZoneOffset truncatedOffset = ZoneOffset.ofTotalSeconds( offsetMinutes * 60 );
return value.withOffsetSameInstant( truncatedOffset );
}
代码示例来源:origin: neo4j/neo4j
@Override
public Value asValue()
{
return TimeZones.validZoneId( zoneId ) ?
DateTimeValue.datetime( epochSecondUTC, nanoOfSecond, ZoneId.of( TimeZones.map( zoneId ) ) ) :
DateTimeValue.datetime( epochSecondUTC, nanoOfSecond, ZoneOffset.ofTotalSeconds( zoneOffsetSeconds ) );
}
代码示例来源:origin: neo4j/neo4j
@Override
public Object read( ReadableClosableChannel from ) throws IOException
{
if ( from.get() == (byte) 0 )
{
long epochSecondsUTC = from.getLong();
int nanos = from.getInt();
int offsetSeconds = from.getInt();
return ZonedDateTime.ofInstant( Instant.ofEpochSecond( epochSecondsUTC, nanos ), ZoneOffset.ofTotalSeconds( offsetSeconds ) );
}
else
{
long epochSecondsUTC = from.getLong();
int nanos = from.getInt();
int zoneID = from.getInt();
String zone = TimeZones.map( (short) zoneID );
return ZonedDateTime.ofInstant( Instant.ofEpochSecond( epochSecondsUTC, nanos ), ZoneId.of( zone ) );
}
}
代码示例来源:origin: neo4j/neo4j
dateTimes[i] =
ZonedDateTime.ofInstant( Instant.ofEpochSecond( epochSecond, nanoOfSecond ),
ZoneOffset.ofTotalSeconds( secondOffset ) );
代码示例来源:origin: neo4j/neo4j
private TimeValue unpackTime() throws IOException
{
long nanosOfDayLocal = unpackLong();
int offsetSeconds = unpackInteger();
return time( TemporalUtil.nanosOfDayToUTC( nanosOfDayLocal, offsetSeconds ), ZoneOffset.ofTotalSeconds( offsetSeconds ) );
}
代码示例来源:origin: neo4j/neo4j
@Override
public Value decodeForTemporal( long[] valueBlocks, int offset )
{
if ( storingZoneOffset( valueBlocks[offset] ) )
{
int nanoOfSecond = (int) (valueBlocks[offset] >>> 33);
checkValidNanoOfSecond( nanoOfSecond );
long epochSecond = valueBlocks[1 + offset];
int secondOffset = (int) valueBlocks[2 + offset];
return DateTimeValue.datetime( epochSecond, nanoOfSecond, ZoneOffset.ofTotalSeconds( secondOffset ) );
}
else
{
int nanoOfSecond = (int) (valueBlocks[offset] >>> 33);
checkValidNanoOfSecond( nanoOfSecond );
long epochSecond = valueBlocks[1 + offset];
short zoneNumber = (short) valueBlocks[2 + offset];
return DateTimeValue.datetime( epochSecond, nanoOfSecond,
ZoneId.of( TimeZones.map( zoneNumber ) ) );
}
}
代码示例来源: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: neo4j/neo4j
private DateTimeValue unpackDateTimeWithZoneOffset() throws IOException
{
long epochSecondLocal = unpackLong();
long nano = unpackLong();
int offsetSeconds = unpackInteger();
return datetime( newZonedDateTime( epochSecondLocal, nano, ZoneOffset.ofTotalSeconds( offsetSeconds ) ) );
}
代码示例来源:origin: neo4j/neo4j
@Override
public ArrayValue decodeArray( Value dataValue )
{
if ( dataValue instanceof LongArray )
{
LongArray numbers = (LongArray) dataValue;
OffsetTime[] times = new OffsetTime[(int) (numbers.length() / BLOCKS_TIME)];
for ( int i = 0; i < times.length; i++ )
{
long nanoOfDay = numbers.longValue( i * BLOCKS_TIME );
int secondOffset = (int) numbers.longValue( i * BLOCKS_TIME + 1 );
checkValidNanoOfDay( nanoOfDay );
times[i] = OffsetTime.of( LocalTime.ofNanoOfDay( nanoOfDay ), ZoneOffset.ofTotalSeconds( secondOffset ) );
}
return Values.timeArray( times );
}
else
{
throw new InvalidRecordException( "Array with unexpected type. Actual:"
+ dataValue.getClass().getSimpleName() + ". Expected: LongArray." );
}
}
},
代码示例来源:origin: neo4j/neo4j
private ZoneOffset randomZoneOffset()
{
return ZoneOffset.ofTotalSeconds( random.nextInt( ZoneOffset.MIN.getTotalSeconds(), ZoneOffset.MAX.getTotalSeconds() ) );
}
代码示例来源:origin: apache/drill
/**
* Best effort parsing of the given value
*/
public static LocalDateTime parseBest(String value) {
TemporalAccessor parsed = getDateTimeFormatter().parse(value);
LocalDate datePart;
LocalTime timePart;
ZoneOffset zoneOffset;
long epochDay = 0, nanoSeconds = 0;
int offsetSeconds = 0;
// get different parsed parts
if (parsed.isSupported(ChronoField.EPOCH_DAY)) {
epochDay = parsed.getLong(ChronoField.EPOCH_DAY);
}
if (parsed.isSupported(ChronoField.NANO_OF_DAY)) {
nanoSeconds = parsed.getLong(ChronoField.NANO_OF_DAY);
}
if (parsed.isSupported(ChronoField.OFFSET_SECONDS)) {
offsetSeconds = parsed.get(ChronoField.OFFSET_SECONDS);
}
zoneOffset = ZoneOffset.ofTotalSeconds(offsetSeconds);
datePart = LocalDate.ofEpochDay(epochDay);
timePart = LocalTime.ofNanoOfDay(nanoSeconds);
return OffsetDateTime.of(datePart, timePart, zoneOffset).toLocalDateTime();
}
内容来源于网络,如有侵权,请联系作者删除!