热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

java.time.temporal.TemporalUnit.getDuration()方法的使用及代码示例

本文整理了Java中java.time.temporal.TemporalUnit.getDuration()方法的一些代码示例,展示了TemporalUn

本文整理了Java中java.time.temporal.TemporalUnit.getDuration()方法的一些代码示例,展示了TemporalUnit.getDuration()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TemporalUnit.getDuration()方法的具体详情如下:
包路径:java.time.temporal.TemporalUnit
类名称:TemporalUnit
方法名:getDuration

TemporalUnit.getDuration介绍

[英]Gets the duration of this unit, which may be an estimate.

All units return a duration measured in standard nanoseconds from this method. The duration will be positive and non-zero. For example, an hour has a duration of 60 * 60 * 1,000,000,000ns.

Some units may return an accurate duration while others return an estimate. For example, days have an estimated duration due to the possibility of daylight saving time changes. To determine if the duration is an estimate, use #isDurationEstimated().
[中]获取此单位的持续时间,它可能是一个估计值。
所有单位都会返回一个持续时间,以该方法中的标准纳秒为单位。持续时间将为正且非零。例如,一小时的持续时间为60601000000000ns。
一些单位可能会返回准确的持续时间,而其他单位则会返回估计值。例如,由于夏令时可能会发生变化,因此天数具有估计的持续时间。要确定持续时间是否为估计值,请使用#isDurationEstimated()。

代码示例

代码示例来源:origin: jtablesaw/tablesaw

return packedTime;
Duration unitDur = unit.getDuration();
if (unitDur.getSeconds() > SECONDS_PER_DAY) {
throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation");

代码示例来源:origin: org.ogema.eval/timeseries-aggregation

public AggregationType(long duration, TemporalUnit unit) {
Objects.requireNonNull(unit);
if (duration <= 0)
throw new IllegalArgumentException("Duration must be positive, got " + duration);
this.duration = duration;
this.unit = unit;
this.hash = (int) duration * unit.hashCode();
this.totalDuration = Duration.ofMillis(unit.getDuration().toMillis() * duration);
}

代码示例来源:origin: org.ogema.eval/timeseries-aggregation

public StandardIntervalTimeSeries(ReadOnlyTimeSeries timeSeries, Class type, TemporalUnit unit, long duration, ZoneId zoneId, InterpolationMode mode,
boolean ignoreGaps, long minGapDuration) {
this.timeSeries = timeSeries;
this.zOneId= zoneId;
this.type = type;
this.unit = unit;
this.duration = duration;
this.mode = mode;
this.totalDuration = unit.getDuration().multipliedBy(duration);
this.ignoreGaps = ignoreGaps;
this.minGapDuration = minGapDuration;
}

代码示例来源:origin: signaflo/java-timeseries

/**
* The total amount of time in this time period measured in seconds, the base SI unit of time.
*
* @return the total amount of time in this time period measured in seconds.
*/
public double totalSeconds() {
final double nanoSecOndsPerSecond= 1E9;
Duration thisDuration = this.timeUnit.getDuration();
double secOnds= thisDuration.getSeconds() * this.periodLength;
double nanos = thisDuration.getNano();
nanos = (nanos * this.periodLength);
nanos = (nanos / nanoSecondsPerSecond);
return seconds + nanos;
}

代码示例来源:origin: org.ogema.eval/timeseries-aggregation

public ReadOnlyTimeSeries build() {
return new StandardIntervalTimeSeries(timeSeries, Float.class, unit, duration, timeZone, mode, ignoreGaps,
minGapDuration != null ? minGapDuration : (2L * unit.getDuration().multipliedBy(duration).toMillis()));
}

代码示例来源:origin: org.ogema.eval/timeseries-aggregation

private static long getNext(long time, TemporalUnit unit, long multiplier, ZoneId zoneId) {
final long end;
try {
if (!unit.isDateBased())
end = time + unit.getDuration().multipliedBy(multiplier).toMillis();
else
end = ZonedDateTime.ofInstant(Instant.ofEpochMilli(time), zoneId).plus(multiplier, unit).toInstant().toEpochMilli();
} catch (ArithmeticException e) {
return multiplier > 0 ? Long.MAX_VALUE : Long.MIN_VALUE;
}
if (multiplier > 0 && end return Long.MAX_VALUE;
else if (multiplier <0 && end > time)
return Long.MIN_VALUE;
return end;
}

代码示例来源:origin: com.github.seratch/java-time-backport

return this;
Duration unitDur = unit.getDuration();
if (unitDur.getSeconds() > LocalTime.SECONDS_PER_DAY) {
throw new DateTimeException("Unit is too large to be used for truncation");

代码示例来源:origin: org.ogema.eval/timeseries-eval-base

@Override
public EvaluationInstance newEvaluation(String id, EvaluationProvider provider, List input,
List requestedResults, Collection configurations) {
final EvaluationInstance instance = provider.newEvaluation(id, input, requestedResults, configurations);
Long timestep = null;
if (configurations != null) {
timestep = configurations.stream()
.filter(cfg -> cfg.getConfigurationType() == TimestepConfiguration.INSTANCE)
.map(cfg -> {
GenericDurationConfiguration duratiOnCfg= (GenericDurationConfiguration) cfg;
final long d = durationCfg.getDuration();
final String unit0 = durationCfg.getUnit();
TemporalUnit unit = ChronoUnit.MILLIS;
try {
unit = ChronoUnit.valueOf(unit0.toUpperCase());
} catch (Exception e) {}
final long totalDuration = unit.getDuration().toMillis() * d;
return totalDuration;
}).findAny().orElse(null);
} else {
timestep = provider.requestedUpdateInterval();
}

final Evaluation eval = new Evaluation(EvaluationUtils.getMultiTimeSeriesIterator(input,
requestedResults, configurations, instance, timestep), instance);
instance.addListener(eval);
Executors.newSingleThreadExecutor().submit(eval);
return instance;
}

代码示例来源:origin: com.github.seratch/java-time-backport

return this;
Duration unitDur = unit.getDuration();
if (unitDur.getSeconds() > SECONDS_PER_DAY) {
throw new DateTimeException("Unit is too large to be used for truncation");

代码示例来源:origin: org.threeten/threeten-extra

long fromNanos = fromUnit.getDuration().toNanos();
long tOnanos= toUnit.getDuration().toNanos();
if (fromNanos > toNanos) {
long multiple = fromNanos / toNanos;

代码示例来源:origin: org.smartrplace.logging/fendodb-tools

private final static long getAlignedIntervalStartTime(ReadOnlyTimeSeries timeSeries, long startTime, long samplingInterval, final ZoneId timeZone) {
final Instant t0;
if (timeSeries != null) {
final SampledValue sv = timeSeries.getNextValue(startTime);
if (sv == null)
return startTime;
t0 = Instant.ofEpochMilli(sv.getTimestamp());
} else {
t0 = Instant.ofEpochMilli(startTime);
}
for (TemporalUnit unit :units) {
if (samplingInterval == unit.getDuration().toMillis()) {
if (!unit.isDateBased())
return t0.truncatedTo(unit).toEpochMilli();
else {
final ZonedDateTime day = ZonedDateTime.ofInstant(t0, timeZone).truncatedTo(ChronoUnit.DAYS);
final ZonedDateTime truncated;
if (unit == ChronoUnit.WEEKS)
truncated = day.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
else if (unit == ChronoUnit.MONTHS)
truncated = day.with(TemporalAdjusters.firstDayOfMonth());
else
truncated = day.with(TemporalAdjusters.firstDayOfYear());
return truncated.toInstant().toEpochMilli();
}
}
}
return startTime;
}

代码示例来源:origin: tech.tablesaw/tablesaw-core

return packedTime;
Duration unitDur = unit.getDuration();
if (unitDur.getSeconds() > SECONDS_PER_DAY) {
throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation");

代码示例来源:origin: com.github.seratch/java-time-backport

case SECONDS: return plusSeconds(amountToAdd);
return plusSeconds(Jdk8Methods.safeMultiply(unit.getDuration().seconds, amountToAdd));
Duration duration = unit.getDuration().multipliedBy(amountToAdd);
return plusSeconds(duration.getSeconds()).plusNanos(duration.getNano());

推荐阅读
  • Java源代码安全审计(二):使用Fortify-sca工具进行maven项目安全审计
    本文介绍了使用Fortify-sca工具对maven项目进行安全审计的过程。作者通过对Fortify的研究和实践,记录了解决问题的学习过程。文章详细介绍了maven项目的处理流程,包括clean、build、Analyze和Report。在安装mvn后,作者遇到了一些错误,并通过Google和Stack Overflow等资源找到了解决方法。作者分享了将一段代码添加到pom.xml中的经验,并成功进行了mvn install。 ... [详细]
  • 本文整理了Java面试中常见的问题及相关概念的解析,包括HashMap中为什么重写equals还要重写hashcode、map的分类和常见情况、final关键字的用法、Synchronized和lock的区别、volatile的介绍、Syncronized锁的作用、构造函数和构造函数重载的概念、方法覆盖和方法重载的区别、反射获取和设置对象私有字段的值的方法、通过反射创建对象的方式以及内部类的详解。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文介绍了Hyperledger Fabric外部链码构建与运行的相关知识,包括在Hyperledger Fabric 2.0版本之前链码构建和运行的困难性,外部构建模式的实现原理以及外部构建和运行API的使用方法。通过本文的介绍,读者可以了解到如何利用外部构建和运行的方式来实现链码的构建和运行,并且不再受限于特定的语言和部署环境。 ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • 本文介绍了Python爬虫技术基础篇面向对象高级编程(中)中的多重继承概念。通过继承,子类可以扩展父类的功能。文章以动物类层次的设计为例,讨论了按照不同分类方式设计类层次的复杂性和多重继承的优势。最后给出了哺乳动物和鸟类的设计示例,以及能跑、能飞、宠物类和非宠物类的增加对类数量的影响。 ... [详细]
  • JDK源码学习之HashTable(附带面试题)的学习笔记
    本文介绍了JDK源码学习之HashTable(附带面试题)的学习笔记,包括HashTable的定义、数据类型、与HashMap的关系和区别。文章提供了干货,并附带了其他相关主题的学习笔记。 ... [详细]
  • 重入锁(ReentrantLock)学习及实现原理
    本文介绍了重入锁(ReentrantLock)的学习及实现原理。在学习synchronized的基础上,重入锁提供了更多的灵活性和功能。文章详细介绍了重入锁的特性、使用方法和实现原理,并提供了类图和测试代码供读者参考。重入锁支持重入和公平与非公平两种实现方式,通过对比和分析,读者可以更好地理解和应用重入锁。 ... [详细]
  • Java 11相对于Java 8,OptaPlanner性能提升有多大?
    本文通过基准测试比较了Java 11和Java 8对OptaPlanner的性能提升。测试结果表明,在相同的硬件环境下,Java 11相对于Java 8在垃圾回收方面表现更好,从而提升了OptaPlanner的性能。 ... [详细]
  • HashMap的相关问题及其底层数据结构和操作流程
    本文介绍了关于HashMap的相关问题,包括其底层数据结构、JDK1.7和JDK1.8的差异、红黑树的使用、扩容和树化的条件、退化为链表的情况、索引的计算方法、hashcode和hash()方法的作用、数组容量的选择、Put方法的流程以及并发问题下的操作。文章还提到了扩容死链和数据错乱的问题,并探讨了key的设计要求。对于对Java面试中的HashMap问题感兴趣的读者,本文将为您提供一些有用的技术和经验。 ... [详细]
  • 本文整理了Java中java.lang.NoSuchMethodError.getMessage()方法的一些代码示例,展示了NoSuchMethodErr ... [详细]
  • 本文整理了常用的CSS属性及用法,包括背景属性、边框属性、尺寸属性、可伸缩框属性、字体属性和文本属性等,方便开发者查阅和使用。 ... [详细]
author-avatar
撒药拿拉的唐小妄
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有