本文整理匯總了Java中java.time.LocalTime.ofNanoOfDay方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalTime.ofNanoOfDay方法的具體用法?Java LocalTime.ofNanoOfDay怎麽用?Java LocalTime.ofNanoOfDay使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.LocalTime
的用法示例。
在下文中一共展示了LocalTime.ofNanoOfDay方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: plusWithOverflow
import java.time.LocalTime; //導入方法依賴的package包/類
private ChronoLocalDateTimeImpl<D> plusWithOverflow(D newDate, long hours, long minutes, long seconds, long nanos) {
// 9223372036854775808 long, 2147483648 int
if ((hours | minutes | seconds | nanos) == 0) {
return with(newDate, time);
}
long totDays = nanos / NANOS_PER_DAY + // max/24*60*60*1B
seconds / SECONDS_PER_DAY + // max/24*60*60
minutes / MINUTES_PER_DAY + // max/24*60
hours / HOURS_PER_DAY; // max/24
long totNanos = nanos % NANOS_PER_DAY + // max 86400000000000
(seconds % SECONDS_PER_DAY) * NANOS_PER_SECOND + // max 86400000000000
(minutes % MINUTES_PER_DAY) * NANOS_PER_MINUTE + // max 86400000000000
(hours % HOURS_PER_DAY) * NANOS_PER_HOUR; // max 86400000000000
long curNoD = time.toNanoOfDay(); // max 86400000000000
totNanos = totNanos + curNoD; // total 432000000000000
totDays += Math.floorDiv(totNanos, NANOS_PER_DAY);
long newNoD = Math.floorMod(totNanos, NANOS_PER_DAY);
LocalTime newTime = (newNoD == curNoD ? time : LocalTime.ofNanoOfDay(newNoD));
return with(newDate.plus(totDays, ChronoUnit.DAYS), newTime);
}
示例2: plusWithOverflow
import java.time.LocalTime; //導入方法依賴的package包/類
private ChronoDateTimeImpl<C> plusWithOverflow(ChronoLocalDate<C> newDate, long hours, long minutes, long seconds,
long nanos) {
// 9223372036854775808 long, 2147483648 int
if ((hours | minutes | seconds | nanos) == 0) {
return with(newDate, this.time);
}
long totDays = nanos / NANOS_PER_DAY + // max/24*60*60*1B
seconds / SECONDS_PER_DAY + // max/24*60*60
minutes / MINUTES_PER_DAY + // max/24*60
hours / HOURS_PER_DAY; // max/24
long totNanos = nanos % NANOS_PER_DAY + // max 86400000000000
(seconds % SECONDS_PER_DAY) * NANOS_PER_SECOND + // max 86400000000000
(minutes % MINUTES_PER_DAY) * NANOS_PER_MINUTE + // max 86400000000000
(hours % HOURS_PER_DAY) * NANOS_PER_HOUR; // max 86400000000000
long curNoD = this.time.toNanoOfDay(); // max 86400000000000
totNanos = totNanos + curNoD; // total 432000000000000
totDays += Jdk8Methods.floorDiv(totNanos, NANOS_PER_DAY);
long newNoD = Jdk8Methods.floorMod(totNanos, NANOS_PER_DAY);
LocalTime newTime = (newNoD == curNoD ? this.time : LocalTime.ofNanoOfDay(newNoD));
return with(newDate.plus(totDays, ChronoUnit.DAYS), newTime);
}
示例3: factory_ofNanoOfDay_singletons
import java.time.LocalTime; //導入方法依賴的package包/類
@Test
public void factory_ofNanoOfDay_singletons() {
for (int i = 0; i < 24; i++) {
LocalTime test1 = LocalTime.ofNanoOfDay(i * 1000000000L * 60L * 60L);
LocalTime test2 = LocalTime.of(i, 0);
assertSame(test1, test2);
}
}
示例4: queryFrom
import java.time.LocalTime; //導入方法依賴的package包/類
@Override
public LocalTime queryFrom(TemporalAccessor temporal) {
if (temporal.isSupported(NANO_OF_DAY)) {
return LocalTime.ofNanoOfDay(temporal.getLong(NANO_OF_DAY));
}
return null;
}
示例5: format
import java.time.LocalTime; //導入方法依賴的package包/類
@Override
public boolean format(DateTimePrintContext context, StringBuilder buf) {
ZoneId zone = context.getValue(TemporalQueries.zoneId());
if (zone == null) {
return false;
}
String zname = zone.getId();
if (!(zone instanceof ZoneOffset)) {
TemporalAccessor dt = context.getTemporal();
int type = GENERIC;
if (!isGeneric) {
if (dt.isSupported(ChronoField.INSTANT_SECONDS)) {
type = zone.getRules().isDaylightSavings(Instant.from(dt)) ? DST : STD;
} else if (dt.isSupported(ChronoField.EPOCH_DAY) &&
dt.isSupported(ChronoField.NANO_OF_DAY)) {
LocalDate date = LocalDate.ofEpochDay(dt.getLong(ChronoField.EPOCH_DAY));
LocalTime time = LocalTime.ofNanoOfDay(dt.getLong(ChronoField.NANO_OF_DAY));
LocalDateTime ldt = date.atTime(time);
if (zone.getRules().getTransition(ldt) == null) {
type = zone.getRules().isDaylightSavings(ldt.atZone(zone).toInstant()) ? DST : STD;
}
}
}
String name = getDisplayName(zname, type, context.getLocale());
if (name != null) {
zname = name;
}
}
buf.append(zname);
return true;
}
示例6: decodeBinary
import java.time.LocalTime; //導入方法依賴的package包/類
@Override
public final LocalTime decodeBinary(final BufferReader b) {
return LocalTime.ofNanoOfDay(b.readLong() * 1000);
}
示例7: decodeBinary
import java.time.LocalTime; //導入方法依賴的package包/類
@Override
public final OffsetTime decodeBinary(final BufferReader b) {
final LocalTime time = LocalTime.ofNanoOfDay(b.readLong() * 1000);
final ZoneOffset zone = ZoneOffset.ofTotalSeconds(-b.readInt());
return time.atOffset(zone);
}
示例8: factory_ofNanoOfDay
import java.time.LocalTime; //導入方法依賴的package包/類
@Test
public void factory_ofNanoOfDay() {
LocalTime localTime = LocalTime.ofNanoOfDay(60 * 60 * 1000000000L + 17);
check(localTime, 1, 0, 0, 17);
}
示例9: factory_ofNanoOfDay_tooLow
import java.time.LocalTime; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofNanoOfDay_tooLow() {
LocalTime.ofNanoOfDay(-1);
}
示例10: factory_ofNanoOfDay_tooHigh
import java.time.LocalTime; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofNanoOfDay_tooHigh() {
LocalTime.ofNanoOfDay(24 * 60 * 60 * 1000000000L);
}
示例11: decodeBinary
import java.time.LocalTime; //導入方法依賴的package包/類
@Override
public LocalTime decodeBinary(int len, ByteBuf buff) {
// micros to nanos
return LocalTime.ofNanoOfDay(buff.readLong() * 1000);
}
示例12: getValue
import java.time.LocalTime; //導入方法依賴的package包/類
@Override
public final LocalTime getValue(long code) {
return code == Long.MIN_VALUE ? null : LocalTime.ofNanoOfDay(code);
}