持续时间类isNegative()方法 (Duration Class isNegative() method)

  • isNegative() method is available in java.time package.

    isNegative()方法在java.time包中可用。

  • isNegative() method is used to check whether this Duration object holds the value of length < 0 (i.e. negative) or not but it excludes value 0.

    isNegative()方法用于检查此Duration对象是否保留length <0(即,负数)的值,但不包含值0。

  • isNegative() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    isNegative()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • isNegative() method does not throw an exception at the time of checking negative value.

    isNegative()方法在检查负值时不会引发异常。

Syntax:

句法:

    public boolean isNegative();

Parameter(s):

参数:

  • None

    没有

Return value:

返回值:

The return type of this method is boolean, it returns true when this Duration holds negative value otherwise it returns false.

此方法的返回类型为boolean ,如果Duration的值为负,则返回true,否则返回false。

Example:

例:

// Java program to demonstrate the example
// of boolean isNegative() method of Duration
import java.time.*;
public class IsNegativeOfDuration {public static void main(String args[]) {// Instantiates two Duration objects
Duration du1 = Duration.ofHours(-10);
Duration du2 = Duration.parse("P1DT2H20M");
// Display du1 and du2
System.out.println("du1: " + du1);
System.out.println("du2: " + du2);
// checks whether the value
// of this Duration (du1) is negative
// or not i.e here it returns true because
// the value of du1 is negative
boolean status = du1.isNegative();
// Display status
System.out.println("du1.isNegative(): " + status);
// checks whether the value
// of this Duration (du2) is negative
// or not i.e here it returns false because
// the value of du2 is positive
status = du2.isNegative();
// Display status
System.out.println("du2.isNegative(): " + status);
}
}

Output

输出量

du1: PT-10H
du2: PT26H20M
du1.isNegative(): true
du2.isNegative(): false

翻译自: https://www.includehelp.com/java/duration-isnegative-method-with-example.aspx

Java Duration类| isNegative()方法与示例相关推荐

  1. java annotation class,Java Class类 isAnnotation()方法及示例

    Class类isAnnotation()方法isAnnotation()方法在java.lang包中可用. isAnnotation()方法用于检查此Class对象是否表示注释类型. isAnnota ...

  2. java字符类型的返回值,Java字符类isWhitespace()方法及示例

    Character 类isWhitespace()法isWhitespace()方法在java.lang包中可用. isWhitespace()方法用于检查给定的char值是否为空格,但是它包含空格中 ...

  3. java日历类add方法_Java日历computeTime()方法及示例

    java日历类add方法 日历类computeTime()方法 (Calendar Class computeTime() method) computeTime() method is availa ...

  4. java日历类add方法_Java日历computeFields()方法及示例

    java日历类add方法 日历类的computeFields()方法 (Calendar Class computeFields() method) computeFields() method is ...

  5. java日历类add方法_Java日历setFirstDayOfWeek()方法与示例

    java日历类add方法 日历类setFirstDayOfWeek()方法 (Calendar Class setFirstDayOfWeek() method) setFirstDayOfWeek( ...

  6. java日历类add方法_Java日历setMinimalDaysInFirstWeek()方法与示例

    java日历类add方法 日历类setMinimalDaysInFirstWeek()方法 (Calendar Class setMinimalDaysInFirstWeek() method) se ...

  7. java散列法的运用实例,Java HashMap compute() 使用方法及示例

    Java HashMap compute() 使用方法及示例 Java HashMap compute()方法计算一个新值,并将其与哈希映射中的指定键相关联. compute()方法的语法为: has ...

  8. Java——String类的方法

    Java--String类的方法 String str1 = "abc" 与String str2 = new String("abc")有什么区别? 字符串常 ...

  9. java播放声音类和一个简单示例

    java播放声音类和一个简单示例 播放声音的类 复制代码 代码如下:  import java.io.File; import java.io.IOException; import javax.so ...

最新文章

  1. 95%PyTorch库都会中招的bug!特斯拉AI总监都没能幸免
  2. H3 BPM微信接入配置
  3. MANIFEST.MF文件全面解析
  4. std::thread 不 join
  5. 巧妙使用信用卡N个小技巧
  6. graphics | 基础绘图系统(八)——棘状图、符号图、多边形(路径)图、Cohen-Friendly关联图、条件密度图...
  7. 独立站卖家不可缺的推广引流?
  8. 基于大数据平台的异常检测场景分析方案
  9. 配置核查保密检查等保工具箱态势感知
  10. windows做软件界面
  11. 关闭计算机主机还亮着,Win10系统电脑关机后主机电源灯依然亮着的解决方法
  12. linux 同步utc时间吗,中国时区utc在服务器上同步的办法
  13. 青海湖:月光尽情倾洒惹人念
  14. BeanDefinitionParsingException Configuration problem Unabl
  15. 2021年度总结,男儿努力平生志
  16. Point-cloud based 3D object detection and classification methods for self-driving applications
  17. 详解比较好的音视频通话SDK开发包的技术要点
  18. JAVA接入讯飞离线合成语音
  19. 676_AUTOSAR_TR_Methodology_文档阅读3
  20. 苹果手机屏幕尺寸和弹出键盘高度总结

热门文章

  1. zblog php 侧边栏样式,ZBlogPHP免费主题Blogs如何修改侧边栏搜索框样式?
  2. mysql binary blob区别_SQL中binary 和 varbinary的区别 blob
  3. rnn神经网络 层次_精讲深度学习RNN三大核心点,三分钟掌握循环神经网络
  4. 分享20个漂亮的DIV CSS标准化站点案例
  5. 《React源码解析》系列完结!
  6. 控制HTML Input只能输入数字和小数点
  7. HBuilder的快捷操作
  8. 如何判断两个时间段是否有交集
  9. OC之OBJC2_UNAVAILABLE
  10. PHP中cookie和session的区别