本文整理汇总了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);
}