本文整理了Java中org.threeten.bp.Instant.getNano()
方法的一些代码示例,展示了Instant.getNano()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instant.getNano()
方法的具体详情如下:
包路径:org.threeten.bp.Instant
类名称:Instant
方法名:getNano
[英]Gets the number of nanoseconds, later along the time-line, from the start of the second.
The nanosecond-of-second value measures the total number of nanoseconds from the second returned by getEpochSecond.
[中]获取从第二个开始沿时间线稍后的纳秒数。
nanosecond of second值测量getEpochSecond返回的第二个纳秒的总纳秒数。
代码示例来源:origin: googleapis/google-cloud-java
/**
* Creates a Timestamp instance from the given string. String is in the RFC 3339 format without
* the timezone offset (always ends in "Z").
*/
public static Timestamp parseTimestamp(String timestamp) {
Instant instant = Instant.parse(timestamp);
return ofTimeSecondsAndNanos(instant.getEpochSecond(), instant.getNano());
}
代码示例来源:origin: com.github.joschi.jackson/jackson-datatype-threetenbp
@Override
public int applyAsInt(Instant value) {
return value.getNano();
}
},
代码示例来源:origin: org.threeten/threetenbp
/**
* Converts an {@code Instant} to a {@code java.sql.Timestamp}.
*
* @param instant the instant, not null
* @return the SQL timestamp, not null
*/
public static Timestamp toSqlTimestamp(Instant instant) {
try {
Timestamp ts = new Timestamp(instant.getEpochSecond() * 1000);
ts.setNanos(instant.getNano());
return ts;
} catch (ArithmeticException ex) {
throw new IllegalArgumentException(ex);
}
}
代码示例来源:origin: ThreeTen/threetenbp
/**
* Converts an {@code Instant} to a {@code java.sql.Timestamp}.
*
* @param instant the instant, not null
* @return the SQL timestamp, not null
*/
public static Timestamp toSqlTimestamp(Instant instant) {
try {
Timestamp ts = new Timestamp(instant.getEpochSecond() * 1000);
ts.setNanos(instant.getNano());
return ts;
} catch (ArithmeticException ex) {
throw new IllegalArgumentException(ex);
}
}
代码示例来源:origin: com.google.cloud/google-cloud-core
/**
* Creates a Timestamp instance from the given string. String is in the RFC 3339 format without
* the timezone offset (always ends in "Z").
*/
public static Timestamp parseTimestamp(String timestamp) {
Instant instant = Instant.parse(timestamp);
return ofTimeSecondsAndNanos(instant.getEpochSecond(), instant.getNano());
}
代码示例来源:origin: ThreeTen/threetenbp
/**
* Obtains an instance of {@code ZonedDateTime} from an {@code Instant}.
* <p>
* This creates a zoned date-time with the same instant as that specified.
* Calling {@link #toInstant()} will return an instant equal to the one used here.
* <p>
* Converting an instant to a zoned date-time is simple as there is only one valid
* offset for each instant.
*
* @param instant the instant to create the date-time from, not null
* @param zone the time-zone, not null
* @return the zoned date-time, not null
* @throws DateTimeException if the result exceeds the supported range
*/
public static ZonedDateTime ofInstant(Instant instant, ZoneId zone) {
Jdk8Methods.requireNonNull(instant, "instant");
Jdk8Methods.requireNonNull(zone, "zone");
return create(instant.getEpochSecond(), instant.getNano(), zone);
}
代码示例来源:origin: org.threeten/threetenbp
/**
* Obtains an instance of {@code ZonedDateTime} from an {@code Instant}.
* <p>
* This creates a zoned date-time with the same instant as that specified.
* Calling {@link #toInstant()} will return an instant equal to the one used here.
* <p>
* Converting an instant to a zoned date-time is simple as there is only one valid
* offset for each instant.
*
* @param instant the instant to create the date-time from, not null
* @param zone the time-zone, not null
* @return the zoned date-time, not null
* @throws DateTimeException if the result exceeds the supported range
*/
public static ZonedDateTime ofInstant(Instant instant, ZoneId zone) {
Jdk8Methods.requireNonNull(instant, "instant");
Jdk8Methods.requireNonNull(zone, "zone");
return create(instant.getEpochSecond(), instant.getNano(), zone);
}
代码示例来源:origin: com.torodb.kvdocument/mongo-converter
@Override
public BsonValue visit(DateTimeValue value, Void arg) {
Instant instant = value.getValue().toInstant(ZoneOffset.UTC);
return new BsonTimestamp(
UnsignedInteger.valueOf(instant.getEpochSecond()).intValue(),
instant.getNano()
);
}
代码示例来源:origin: ThreeTen/threetenbp
@Override
public Instant instant() {
if ((tickNanos % 1000000) == 0) {
long millis = baseClock.millis();
return Instant.ofEpochMilli(millis - Jdk8Methods.floorMod(millis, tickNanos / 1000000L));
}
Instant instant = baseClock.instant();
long nanos = instant.getNano();
long adjust = Jdk8Methods.floorMod(nanos, tickNanos);
return instant.minusNanos(adjust);
}
@Override
代码示例来源:origin: org.threeten/threetenbp
@Override
public Instant instant() {
if ((tickNanos % 1000000) == 0) {
long millis = baseClock.millis();
return Instant.ofEpochMilli(millis - Jdk8Methods.floorMod(millis, tickNanos / 1000000L));
}
Instant instant = baseClock.instant();
long nanos = instant.getNano();
long adjust = Jdk8Methods.floorMod(nanos, tickNanos);
return instant.minusNanos(adjust);
}
@Override
代码示例来源:origin: ThreeTen/threetenbp
/**
* Obtains an instance of {@code LocalDateTime} from an {@code Instant} and zone ID.
* <p>
* This creates a local date-time based on the specified instant.
* First, the offset from UTC/Greenwich is obtained using the zone ID and instant,
* which is simple as there is only one valid offset for each instant.
* Then, the instant and offset are used to calculate the local date-time.
*
* @param instant the instant to create the date-time from, not null
* @param zone the time-zone, which may be an offset, not null
* @return the local date-time, not null
* @throws DateTimeException if the result exceeds the supported range
*/
public static LocalDateTime ofInstant(Instant instant, ZoneId zone) {
Jdk8Methods.requireNonNull(instant, "instant");
Jdk8Methods.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant);
return ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset);
}
代码示例来源:origin: ThreeTen/threetenbp
/**
* Obtains the current date-time from the specified clock.
* <p>
* This will query the specified clock to obtain the current date-time.
* Using this method allows the use of an alternate clock for testing.
* The alternate clock may be introduced using {@link Clock dependency injection}.
*
* @param clock the clock to use, not null
* @return the current date-time, not null
*/
public static LocalDateTime now(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock");
final Instant now = clock.instant(); // called once
ZoneOffset offset = clock.getZone().getRules().getOffset(now);
return ofEpochSecond(now.getEpochSecond(), now.getNano(), offset);
}
代码示例来源:origin: org.threeten/threetenbp
/**
* Obtains an instance of {@code LocalDateTime} from an {@code Instant} and zone ID.
* <p>
* This creates a local date-time based on the specified instant.
* First, the offset from UTC/Greenwich is obtained using the zone ID and instant,
* which is simple as there is only one valid offset for each instant.
* Then, the instant and offset are used to calculate the local date-time.
*
* @param instant the instant to create the date-time from, not null
* @param zone the time-zone, which may be an offset, not null
* @return the local date-time, not null
* @throws DateTimeException if the result exceeds the supported range
*/
public static LocalDateTime ofInstant(Instant instant, ZoneId zone) {
Jdk8Methods.requireNonNull(instant, "instant");
Jdk8Methods.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant);
return ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset);
}
代码示例来源:origin: org.threeten/threetenbp
/**
* Obtains the current date-time from the specified clock.
* <p>
* This will query the specified clock to obtain the current date-time.
* Using this method allows the use of an alternate clock for testing.
* The alternate clock may be introduced using {@link Clock dependency injection}.
*
* @param clock the clock to use, not null
* @return the current date-time, not null
*/
public static LocalDateTime now(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock");
final Instant now = clock.instant(); // called once
ZoneOffset offset = clock.getZone().getRules().getOffset(now);
return ofEpochSecond(now.getEpochSecond(), now.getNano(), offset);
}
代码示例来源:origin: ThreeTen/threetenbp
/**
* Obtains an instance from an instant using the specified time-zone.
*
* @param chrono the chronology, not null
* @param instant the instant, not null
* @param zone the zone identifier, not null
* @return the zoned date-time, not null
*/
static <R extends ChronoLocalDate> ChronoZonedDateTimeImpl<R> ofInstant(Chronology chrono, Instant instant, ZoneId zone) {
ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant);
Jdk8Methods.requireNonNull(offset, "offset"); // protect against bad ZoneRules
LocalDateTime ldt = LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset);
@SuppressWarnings("unchecked")
ChronoLocalDateTimeImpl<R> cldt = (ChronoLocalDateTimeImpl<R>) chrono.localDateTime(ldt);
return new ChronoZonedDateTimeImpl<R>(cldt, offset, zone);
}
代码示例来源:origin: org.threeten/threetenbp
/**
* Obtains an instance from an instant using the specified time-zone.
*
* @param chrono the chronology, not null
* @param instant the instant, not null
* @param zone the zone identifier, not null
* @return the zoned date-time, not null
*/
static <R extends ChronoLocalDate> ChronoZonedDateTimeImpl<R> ofInstant(Chronology chrono, Instant instant, ZoneId zone) {
ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant);
Jdk8Methods.requireNonNull(offset, "offset"); // protect against bad ZoneRules
LocalDateTime ldt = LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset);
@SuppressWarnings("unchecked")
ChronoLocalDateTimeImpl<R> cldt = (ChronoLocalDateTimeImpl<R>) chrono.localDateTime(ldt);
return new ChronoZonedDateTimeImpl<R>(cldt, offset, zone);
}
代码示例来源:origin: ThreeTen/threetenbp
/**
* Obtains an instance of {@code OffsetDateTime} from an {@code Instant} and zone ID.
* <p>
* This creates an offset date-time with the same instant as that specified.
* Finding the offset from UTC/Greenwich is simple as there is only one valid
* offset for each instant.
*
* @param instant the instant to create the date-time from, not null
* @param zone the time-zone, which may be an offset, not null
* @return the offset date-time, not null
* @throws DateTimeException if the result exceeds the supported range
*/
public static OffsetDateTime ofInstant(Instant instant, ZoneId zone) {
Jdk8Methods.requireNonNull(instant, "instant");
Jdk8Methods.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant);
LocalDateTime ldt = LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset);
return new OffsetDateTime(ldt, offset);
}
代码示例来源:origin: org.threeten/threetenbp
/**
* Obtains an instance of {@code OffsetDateTime} from an {@code Instant} and zone ID.
* <p>
* This creates an offset date-time with the same instant as that specified.
* Finding the offset from UTC/Greenwich is simple as there is only one valid
* offset for each instant.
*
* @param instant the instant to create the date-time from, not null
* @param zone the time-zone, which may be an offset, not null
* @return the offset date-time, not null
* @throws DateTimeException if the result exceeds the supported range
*/
public static OffsetDateTime ofInstant(Instant instant, ZoneId zone) {
Jdk8Methods.requireNonNull(instant, "instant");
Jdk8Methods.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant);
LocalDateTime ldt = LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset);
return new OffsetDateTime(ldt, offset);
}
代码示例来源:origin: ThreeTen/threetenbp
/**
* Obtains the current time from the specified clock.
* <p>
* This will query the specified clock to obtain the current time.
* Using this method allows the use of an alternate clock for testing.
* The alternate clock may be introduced using {@link Clock dependency injection}.
*
* @param clock the clock to use, not null
* @return the current time, not null
*/
public static LocalTime now(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock");
// inline OffsetTime factory to avoid creating object and InstantProvider checks
final Instant now = clock.instant(); // called once
ZoneOffset offset = clock.getZone().getRules().getOffset(now);
long secsOfDay = now.getEpochSecond() % SECONDS_PER_DAY;
secsOfDay = (secsOfDay + offset.getTotalSeconds()) % SECONDS_PER_DAY;
if (secsOfDay < 0) {
secsOfDay += SECONDS_PER_DAY;
}
return LocalTime.ofSecondOfDay(secsOfDay, now.getNano());
}
代码示例来源:origin: org.threeten/threetenbp
/**
* Obtains the current time from the specified clock.
* <p>
* This will query the specified clock to obtain the current time.
* Using this method allows the use of an alternate clock for testing.
* The alternate clock may be introduced using {@link Clock dependency injection}.
*
* @param clock the clock to use, not null
* @return the current time, not null
*/
public static LocalTime now(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock");
// inline OffsetTime factory to avoid creating object and InstantProvider checks
final Instant now = clock.instant(); // called once
ZoneOffset offset = clock.getZone().getRules().getOffset(now);
long secsOfDay = now.getEpochSecond() % SECONDS_PER_DAY;
secsOfDay = (secsOfDay + offset.getTotalSeconds()) % SECONDS_PER_DAY;
if (secsOfDay < 0) {
secsOfDay += SECONDS_PER_DAY;
}
return LocalTime.ofSecondOfDay(secsOfDay, now.getNano());
}
内容来源于网络,如有侵权,请联系作者删除!