本文整理了Java中java.time.ZonedDateTime.getNano()
方法的一些代码示例,展示了ZonedDateTime.getNano()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZonedDateTime.getNano()
方法的具体详情如下:
包路径:java.time.ZonedDateTime
类名称:ZonedDateTime
方法名:getNano
[英]Gets the nano-of-second field.
[中]获取第二个字段的nano。
代码示例来源: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
@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
public static byte[] encodeDateTimeArray( ZonedDateTime[] dateTimes )
{
// We could store this in dateTimes.length * 2.5 if we wanted
long[] data = new long[dateTimes.length * BLOCKS_DATETIME];
int i;
for ( i = 0; i < dateTimes.length; i++ )
{
data[i * BLOCKS_DATETIME] = dateTimes[i].toEpochSecond();
data[i * BLOCKS_DATETIME + 1] = dateTimes[i].getNano();
if ( dateTimes[i].getZone() instanceof ZoneOffset )
{
ZoneOffset offset = (ZoneOffset) dateTimes[i].getZone();
int secondOffset = offset.getTotalSeconds();
// Set lowest bit to 1 means offset
data[i * BLOCKS_DATETIME + 2] = secondOffset << 1 | 1L;
}
else
{
String timeZoneId = dateTimes[i].getZone().getId();
short zoneNumber = TimeZones.map( timeZoneId );
// Set lowest bit to 0 means zone id
data[i * BLOCKS_DATETIME + 2] = zoneNumber << 1;
}
}
TemporalHeader header = new TemporalHeader( TemporalType.TEMPORAL_DATE_TIME.temporalType );
byte[] bytes = DynamicArrayStore.encodeFromNumbers( data, DynamicArrayStore.TEMPORAL_HEADER_SIZE );
header.writeArrayHeaderTo( bytes );
return bytes;
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public int getNano() {
return dt.getNano();
}
代码示例来源: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: 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: debezium/debezium
private void assertTimestamp(String c4) {
// '2014-09-08 17:51:04.777'
// MySQL container is in UTC and the test time is during summer time period
ZonedDateTime expectedTimestamp = ZonedDateTime.ofInstant(
LocalDateTime.parse("2014-09-08T17:51:04.780").atZone(ZoneId.of("US/Samoa")).toInstant(),
ZoneId.systemDefault());
ZoneId defaultZoneId = ZoneId.systemDefault();
ZonedDateTime c4DateTime = ZonedDateTime.parse(c4, ZonedTimestamp.FORMATTER).withZoneSameInstant(defaultZoneId);
assertThat(c4DateTime.getYear()).isEqualTo(expectedTimestamp.getYear());
assertThat(c4DateTime.getMonth()).isEqualTo(expectedTimestamp.getMonth());
assertThat(c4DateTime.getDayOfMonth()).isEqualTo(expectedTimestamp.getDayOfMonth());
assertThat(c4DateTime.getHour()).isEqualTo(expectedTimestamp.getHour());
assertThat(c4DateTime.getMinute()).isEqualTo(expectedTimestamp.getMinute());
assertThat(c4DateTime.getSecond()).isEqualTo(expectedTimestamp.getSecond());
assertThat(c4DateTime.getNano()).isEqualTo(expectedTimestamp.getNano());
// We're running the connector in the same timezone as the server, so the timezone in the timestamp
// should match our current offset ...
LocalDateTime expectedLocalDateTime = LocalDateTime.parse("2014-09-08T17:51:04.780");
ZoneOffset expectedOffset = defaultZoneId.getRules().getOffset(expectedLocalDateTime);
assertThat(c4DateTime.getOffset()).isEqualTo(expectedOffset);
}
代码示例来源:origin: benas/random-beans
@Override
public ZonedDateTime getRandomValue() {
long minSeconds = min.toEpochSecond();
long maxSeconds = max.toEpochSecond();
long seconds = (long) nextDouble(minSeconds, maxSeconds);
int minNanoSeconds = min.getNano();
int maxNanoSeconds = max.getNano();
long nanoSeconds = (long) nextDouble(minNanoSeconds, maxNanoSeconds);
return ZonedDateTime.ofInstant(Instant.ofEpochSecond(seconds, nanoSeconds), min.getZone());
}
代码示例来源:origin: ebean-orm/ebean
@Override
protected String toJsonNanos(ZonedDateTime value) {
return toJsonNanos(value.toEpochSecond(), value.getNano());
}
代码示例来源:origin: apache/tinkerpop
@Override
public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final O output, final ZonedDateTime zonedDateTime) {
output.writeInt(zonedDateTime.getYear());
output.writeInt(zonedDateTime.getMonthValue());
output.writeInt(zonedDateTime.getDayOfMonth());
output.writeInt(zonedDateTime.getHour());
output.writeInt(zonedDateTime.getMinute());
output.writeInt(zonedDateTime.getSecond());
output.writeInt(zonedDateTime.getNano());
output.writeString(zonedDateTime.getZone().getId());
}
代码示例来源:origin: io.prestosql.benchto/benchto-driver
public GraphiteEventRequestBuilder when(ZonedDateTime zonedDateTime)
{
requireNonNull(zonedDateTime, "zonedDateTime cannot be null");
request.when = new BigDecimal(format("%d.%d", zonedDateTime.toEpochSecond(), zonedDateTime.getNano() / 1000));
return this;
}
代码示例来源:origin: robward-scisys/sldeditor
/**
* Removes the nano seconds from the current time so the time is output without nano-seconds.
*/
private void removeNanoSeconds() {
date = date.minusNanos(date.getNano());
}
代码示例来源:origin: org.jadira.usertype/usertype.core
@Override
public Timestamp toNonNullValue(ZonedDateTime value) {
final Timestamp timestamp = new Timestamp((value.toEpochSecond() * MILLIS_IN_SECOND));
timestamp.setNanos(value.getNano());
return timestamp;
}
代码示例来源:origin: io.github.benas/random-beans
@Override
public ZonedDateTime getRandomValue() {
long minSeconds = min.toEpochSecond();
long maxSeconds = max.toEpochSecond();
long seconds = (long) nextDouble(minSeconds, maxSeconds);
int minNanoSeconds = min.getNano();
int maxNanoSeconds = max.getNano();
long nanoSeconds = (long) nextDouble(minNanoSeconds, maxNanoSeconds);
return ZonedDateTime.ofInstant(Instant.ofEpochSecond(seconds, nanoSeconds), min.getZone());
}
代码示例来源:origin: org.avaje.ebean/ebean
@Override
protected String toJsonNanos(ZonedDateTime value) {
return toJsonNanos(value.toEpochSecond(), value.getNano());
}
代码示例来源:origin: org.tiogasolutions.dev/tioga-dev-common
public ZonedDateTime toFirstDate(ZonedDateTime date) {
return (date == null) ? null : ZonedDateTime.of(date.getYear(), date.getMonthValue(), 1,
date.getHour(), date.getMinute(), date.getSecond(), date.getNano(), date.getZone());
}
}
代码示例来源:origin: org.tiogasolutions.dev/tioga-dev-common
public ZonedDateTime toLastDate(ZonedDateTime date) {
YearMonth yearMonth = toYearMonth(date);
int lastDayOfMonth = yearMonth.lengthOfMonth();
return (date == null) ? null : ZonedDateTime.of(date.getYear(), date.getMonthValue(), lastDayOfMonth,
date.getHour(), date.getMinute(), date.getSecond(), date.getNano(), date.getZone());
}
代码示例来源:origin: no.ssb.lds/linked-data-store-persistence-provider-foundationdb
static Tuple toTuple(ZonedDateTime timestamp) {
return Tuple.from(
-timestamp.getYear(),
-timestamp.getMonth().getValue(),
-timestamp.getDayOfMonth(),
-timestamp.getHour(),
-timestamp.getMinute(),
-timestamp.getSecond(),
-TimeUnit.NANOSECONDS.toMillis(timestamp.getNano())
);
}
代码示例来源:origin: infiniteautomation/ma-core-public
/**
* @param runtime
* @return
*/
public static TimeValue get(ZonedDateTime runtime) {
TimeValue value = new TimeValue();
value.setHour(runtime.getHour());
value.setMinute(runtime.getMinute());
value.setSecond(runtime.getSecond());
value.setMillisecond(runtime.getNano()/1000000);
return value;
}
代码示例来源:origin: org.apache.tinkerpop/gremlin-core
@Override
public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final O output, final ZonedDateTime zonedDateTime) {
output.writeInt(zonedDateTime.getYear());
output.writeInt(zonedDateTime.getMonthValue());
output.writeInt(zonedDateTime.getDayOfMonth());
output.writeInt(zonedDateTime.getHour());
output.writeInt(zonedDateTime.getMinute());
output.writeInt(zonedDateTime.getSecond());
output.writeInt(zonedDateTime.getNano());
output.writeString(zonedDateTime.getZone().getId());
}
内容来源于网络,如有侵权,请联系作者删除!