本文整理了Java中java.time.ZoneOffset.getTotalSeconds()
方法的一些代码示例,展示了ZoneOffset.getTotalSeconds()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneOffset.getTotalSeconds()
方法的具体详情如下:
包路径:java.time.ZoneOffset
类名称:ZoneOffset
方法名:getTotalSeconds
[英]Gets the total zone offset in seconds.
This is the primary way to access the offset amount. It returns the total of the hours, minutes and seconds fields as a single offset that can be added to a time.
[中]获取以秒为单位的总区域偏移量。
这是获取抵销金额的主要方式。它将小时、分钟和秒字段的总数作为可添加到时间中的单个偏移量返回。
代码示例来源:origin: neo4j/neo4j
@Override
int unsafeCompareTo( Value otherValue )
{
TimeValue other = (TimeValue) otherValue;
int compare = Long.compare( nanosOfDayUTC, other.nanosOfDayUTC );
if ( compare == 0 )
{
compare = Integer.compare( value.getOffset().getTotalSeconds(), other.value.getOffset().getTotalSeconds() );
}
return compare;
}
代码示例来源:origin: neo4j/neo4j
@Override
public void writeTime( OffsetTime offsetTime )
{
buf.putLong( TemporalUtil.getNanosOfDayUTC( offsetTime ) );
buf.putInt( offsetTime.getOffset().getTotalSeconds() );
}
代码示例来源:origin: embulk/embulk
/**
* Converts java.time.ZoneOffset to its corresponding org.joda.time.DateTimeZone.
*/
public static org.joda.time.DateTimeZone convertZoneOffsetToJodaDateTimeZone(final ZoneOffset zoneOffset) {
return org.joda.time.DateTimeZone.forOffsetMillis(zoneOffset.getTotalSeconds() * 1000);
}
代码示例来源:origin: org.postgresql/postgresql
private void appendTimeZone(StringBuilder sb, ZoneOffset offset) {
int offsetSeconds = offset.getTotalSeconds();
appendTimeZone(sb, offsetSeconds);
}
代码示例来源:origin: neo4j/neo4j
@Override
public final void writeTime( OffsetTime offsetTime ) throws E
{
long nanosOfDayUTC = TemporalUtil.getNanosOfDayUTC( offsetTime );
int offsetSeconds = offsetTime.getOffset().getTotalSeconds();
writeTime( nanosOfDayUTC, offsetSeconds );
}
代码示例来源: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
private ZoneOffset randomZoneOffset()
{
return ZoneOffset.ofTotalSeconds( random.nextInt( ZoneOffset.MIN.getTotalSeconds(), ZoneOffset.MAX.getTotalSeconds() ) );
}
代码示例来源:origin: neo4j/neo4j
@Override
public void writeDateTime( ZonedDateTime zonedDateTime )
{
buf.putLong( zonedDateTime.toEpochSecond() );
buf.putInt( zonedDateTime.getNano() );
final ZoneId zone = zonedDateTime.getZone();
if ( zone instanceof ZoneOffset )
{
final int offsetSeconds = ((ZoneOffset) zone).getTotalSeconds();
// lowest bit set to 0: it's a zone offset in seconds
buf.putInt( offsetSeconds << 1 );
}
else
{
// lowest bit set to 1: it's a zone id
final int zoneId = (TimeZones.map( zone.getId() ) << 1) | 1;
buf.putInt( zoneId );
}
}
}
代码示例来源:origin: neo4j/neo4j
public static long getNanosOfDayUTC( OffsetTime value )
{
long secondsOfDayLocal = value.toLocalTime().toSecondOfDay();
long secondsOffset = value.getOffset().getTotalSeconds();
return (secondsOfDayLocal - secondsOffset) * NANOS_PER_SECOND + value.getNano();
}
}
代码示例来源:origin: neo4j/neo4j
@Override
public void write( Object value, FlushableChannel into ) throws IOException
{
OffsetTime ot = (OffsetTime) value;
into.putLong( TemporalUtil.getNanosOfDayUTC( ot ) );
into.putInt( ot.getOffset().getTotalSeconds() );
}
} );
代码示例来源:origin: neo4j/neo4j
public static byte[] encodeTimeArray( OffsetTime[] times )
{
// We could store this in dateTimes.length * 1.5 if we wanted
long[] data = new long[(int) (Math.ceil( times.length * BLOCKS_TIME ))];
int i;
for ( i = 0; i < times.length; i++ )
{
data[i * BLOCKS_TIME] = times[i].toLocalTime().toNanoOfDay();
data[i * BLOCKS_TIME + 1] = times[i].getOffset().getTotalSeconds();
}
TemporalHeader header = new TemporalHeader( TemporalType.TEMPORAL_TIME.temporalType );
byte[] bytes = DynamicArrayStore.encodeFromNumbers( data, DynamicArrayStore.TEMPORAL_HEADER_SIZE );
header.writeArrayHeaderTo( bytes );
return bytes;
}
代码示例来源:origin: neo4j/neo4j
@Override
public void writeTime( OffsetTime offsetTime ) throws IOException
{
long nanosOfDayLocal = offsetTime.toLocalTime().toNanoOfDay();
int offsetSeconds = offsetTime.getOffset().getTotalSeconds();
packStructHeader( TIME_SIZE, TIME );
pack( nanosOfDayLocal );
pack( offsetSeconds );
}
代码示例来源:origin: neo4j/neo4j
@Override
public final void writeDateTime( ZonedDateTime zonedDateTime ) throws E
{
long epochSecondUTC = zonedDateTime.toEpochSecond();
int nano = zonedDateTime.getNano();
ZoneId zone = zonedDateTime.getZone();
if ( zone instanceof ZoneOffset )
{
int offsetSeconds = ((ZoneOffset) zone).getTotalSeconds();
writeDateTime( epochSecondUTC, nano, offsetSeconds );
}
else
{
String zoneId = zone.getId();
writeDateTime( epochSecondUTC, nano, zoneId );
}
}
代码示例来源: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: 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: neo4j/neo4j
@Test
void shouldGetNanosOfDayUTC()
{
LocalTime localTime = LocalTime.of( 14, 19, 18, 123999 );
ZoneOffset offset = ZoneOffset.ofHours( -12 );
OffsetTime time = OffsetTime.of( localTime, offset );
long nanosOfDayUTC = TemporalUtil.getNanosOfDayUTC( time );
long expectedNanosOfDayUTC = Duration.ofSeconds( localTime.toSecondOfDay() )
.minus( offset.getTotalSeconds(), SECONDS )
.toNanos();
assertEquals( expectedNanosOfDayUTC + localTime.getNano(), nanosOfDayUTC );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
void shouldReportTooHighOffsetSecondDateTimeRecord()
{
// given
PropertyRecord property = inUse( new PropertyRecord( 42 ) );
final int keyId = 6;
add( inUse( new PropertyKeyTokenRecord( keyId ) ) );
final long[] longs = TemporalType.encodeDateTime( keyId, 1,1, ZoneOffset.MAX.getTotalSeconds() + 1 );
expectInvalidPropertyValue( property, longs );
}
代码示例来源:origin: neo4j/neo4j
@Test
void shouldReportTooHighOffsetSecondTimeRecord()
{
// given
PropertyRecord property = inUse( new PropertyRecord( 42 ) );
final int keyId = 6;
add( inUse( new PropertyKeyTokenRecord( keyId ) ) );
final long[] longs = TemporalType.encodeTime( keyId, 1, ZoneOffset.MAX.getTotalSeconds() + 1 );
expectInvalidPropertyValue( property, longs );
}
代码示例来源:origin: neo4j/neo4j
@Override
public void write( Object value, FlushableChannel into ) throws IOException
{
ZonedDateTime zonedDateTime = (ZonedDateTime) value;
long epochSecondUTC = zonedDateTime.toEpochSecond();
int nano = zonedDateTime.getNano();
ZoneId zone = zonedDateTime.getZone();
if ( zone instanceof ZoneOffset )
{
int offsetSeconds = ((ZoneOffset) zone).getTotalSeconds();
into.put( (byte) 0 );
into.putLong( epochSecondUTC );
into.putInt( nano );
into.putInt( offsetSeconds );
}
else
{
String zoneId = zone.getId();
into.put( (byte) 1 );
into.putLong( epochSecondUTC );
into.putInt( nano );
into.putInt( TimeZones.map( zoneId ) );
}
}
} );
代码示例来源: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 );
}
}
}
内容来源于网络,如有侵权,请联系作者删除!