找到关于编程的34423 篇文章

Java 中的 Duration ofDays() 方法

karthikeya Boyini
更新于 2019年7月30日 22:30:25

93 次浏览

可以使用 Java 中 Duration 类的 ofDays() 方法以 24 小时格式获取持续时间。此方法需要一个参数,即天数,它返回 24 小时格式的持续时间。如果超过持续时间的容量,则会抛出 ArithmeticException。演示此方法的程序如下所示:示例 实时演示 import java.time.Duration; public class Demo { public static void main(String[] args) { long days = 1; Duration duration = Duration.ofDays(days); ... 阅读更多

Java 中的 MonthDay get() 方法

Samual Sam
更新于 2019年7月30日 22:30:25

81 次浏览

可以使用 Java 中 MonthDay 类的 get() 方法获取 MonthDay 中指定字段的值。此方法需要一个参数,即所需的 ChronoField,它返回 MonthDay 中指定字段的值。演示此方法的程序如下所示:示例 实时演示 import java.time.*; import java.time.temporal.*; public class Demo { public static void main(String[] args) { MonthDay md = MonthDay.parse("--02-22"); System.out.println("The MonthDay is: " + md); System.out.println("The ... 阅读更多

Java 中的 MonthDay query() 方法

karthikeya Boyini
更新于 2019年7月30日 22:30:25

67 次浏览

可以使用 Java 中 MonthDay 类的 query 方法根据需要查询 MonthDay 对象。此方法需要一个参数,即要调用的查询,它返回查询的结果。演示此方法的程序如下所示:示例 实时演示 import java.time.*; import java.time.temporal.*; public class Demo { public static void main(String[] args) { MonthDay md = MonthDay.parse("--02-22"); System.out.println("The MonthDay is: " + md); String chronology = md.query(TemporalQueries.chronology()).toString(); ... 阅读更多

Java 中的 MonthDay with() 方法

Samual Sam
更新于 2019年7月30日 22:30:25

65 次浏览

可以使用 Java 中 MonthDay 类的 with() 方法创建 MonthDay 的不可变副本,并根据需要更改月份。此方法需要一个参数,即要在 MonthDay 中设置的月份,它返回一个修改后的月份的 MonthDay。演示此方法的程序如下所示:示例 实时演示 import java.time.*; public class Demo { public static void main(String[] args) { MonthDay md1 = MonthDay.parse("--02-22"); System.out.println("The MonthDay ... 阅读更多

Java 中的 MonthDay withDayOfMonth() 方法

karthikeya Boyini
更新于 2019年7月30日 22:30:25

73 次浏览

可以使用 Java 中 MonthDay 类的 withDayOfMonth() 方法创建 MonthDay 的不可变副本,并根据需要更改月份中的天数。此方法需要一个参数,即要在 MonthDay 中设置的月份中的天数,它返回一个修改后的月份中的天数的 MonthDay。演示此方法的程序如下所示:示例 实时演示 import java.time.*; public class Demo { public static void main(String[] args) { MonthDay md1 = MonthDay.parse("--02-22"); System.out.println("The MonthDay ... 阅读更多

Java 中的 MonthDay withMonth() 方法

Samual Sam
更新于 2019年7月30日 22:30:25

78 次浏览

可以使用 Java 中 MonthDay 类的 withMonth() 方法创建 MonthDay 的不可变副本,并根据需要更改月份。此方法需要一个参数,即要在 MonthDay 中设置的月份,它返回一个修改后的月份的 MonthDay。演示此方法的程序如下所示:示例 实时演示 import java.time.*; public class Demo { public static void main(String[] args) { MonthDay md1 = MonthDay.parse("--02-22"); System.out.println("The MonthDay is: " + md1); ... 阅读更多

Java 中的 MonthDay toString() 方法

karthikeya Boyini
更新于 2019年7月30日 22:30:25

112 次浏览

可以使用 Java 中 MonthDay 类的 toString() 方法获取 MonthDay 对象的字符串值。此方法不需要参数,它返回 MonthDay 对象的字符串值。演示此方法的程序如下所示:示例 实时演示 import java.time.*; public class Demo { public static void main(String[] args) { MonthDay md = MonthDay.parse("--02-22"); System.out.println("The MonthDay is: " + md.toString()); } }输出 The MonthDay is: --02-22现在让我们了解上面的程序。MonthDay 的字符串值 ... 阅读更多

Java 中的 Duration ofMinutes() 方法

Samual Sam
更新于 2019年7月30日 22:30:25

97 次浏览

可以使用 Java 中 Duration 类的 ofMinutes() 方法以一分钟格式获取持续时间。此方法需要一个参数,即分钟数,它返回一分钟格式的持续时间。如果超过持续时间的容量,则会抛出 ArithmeticException。演示此方法的程序如下所示:示例 实时演示 import java.time.Duration; public class Demo { public static void main(String[] args) { long minutes = 2; Duration duration = Duration.ofMinutes(minutes); ... 阅读更多

Java 中的 Duration isZero() 方法

karthikeya Boyini
更新于 2019年7月30日 22:30:25

84 次浏览

可以使用 Java 中 Duration 类的 isZero() 方法检查持续时间是否为零长度。此方法不需要参数。此外,如果持续时间为零长度,则返回 true,否则返回 false。演示此方法的程序如下所示:示例 实时演示 import java.time.Duration; public class Demo { public static void main(String[] args) { Duration d = Duration.ofHours(1); boolean flag = d.isZero(); System.out.println("The duration is: " + d); ... 阅读更多

Java 中的 Duration isNegative() 方法

Samual Sam
更新于 2019年7月30日 22:30:25

83 次浏览

可以使用 Java 中 Duration 类的 isNegative() 方法检查持续时间是否为负。此方法不需要参数。此外,如果持续时间为负,则返回 true,否则返回 false。演示此方法的程序如下所示:示例 实时演示 import java.time.Duration; public class Demo { public static void main(String[] args) { Duration d = Duration.ofSeconds(5); boolean flag = d.isNegative(); System.out.println("The duration is: " + d); if(flag) System.out.println("The above duration is negative"); else ... 阅读更多

广告
© . All rights reserved.