java 根据类名示例化类
LocalDateTime类isBefore()方法 (LocalDateTime Class isBefore() method)
isBefore() method is available in java.time package.
isBefore()方法在java.time包中可用。
isBefore() method is used to check whether this date-time value comes before the given date-time (l_datetime) value or not.
isBefore()方法用于检查此日期时间值是否早于给定的日期时间(l_datetime)值。
isBefore() 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.
isBefore()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
isBefore() method does not throw an exception at the time of checking the status.
isBefore()方法在检查状态时不会引发异常。
Syntax:
句法:
public boolean isBefore(ChronoLocalDateTime l_datetime);
Parameter(s):
参数:
ChronoLocalDateTime l_datetime – represents the ChronoLocalDateTime object to be compared with this LocalDateTime.
ChronoLocalDateTime l_datetime –表示要与该LocalDateTime比较的ChronoLocalDateTime对象。
Return value:
返回值:
The return type of this method is boolean, it returns true when this date-time value comes before the given date-time value otherwise it returns false.
此方法的返回类型为boolean ,如果此日期时间值早于给定的日期时间值,则返回true,否则返回false。
Example:
例:
// Java program to demonstrate the example
// of isBefore(ChronoLocalDateTime l_datetime) method
// of LocalDateTime
import java.time.*;
public class IsBeforeOfLocalDateTime {
public static void main(String args[]) {
// Instantiates two LocalDateTime
LocalDateTime da_ti1 = LocalDateTime.parse("2005-10-05T10:10:10.00");
LocalDateTime da_ti2 = LocalDateTime.now();
// Display da_ti1, da_ti2
System.out.println("LocalDateTime da_ti1 and da_ti2: ");
System.out.println("da_ti1: " + da_ti1);
System.out.println("da_ti2: " + da_ti2);
System.out.println();
// Here, this method checks whether this
// date-time object (da_ti1) comes before
// the given date-time object (da_ti2) or
// not i.e. here it returns true because
// da_ti1 comes before da_ti2
boolean status = da_ti1.isBefore(da_ti2);
// Display status
System.out.print("da_ti1.isBefore(da_ti2): ");
System.out.println(status);
// Here, this method checks whether this
// date-time object (da_ti2) comes before
// the given date-time object (da_ti1) or
// not i.e. here it returns false because
// da_ti2 comes after da_ti1
status = da_ti2.isBefore(da_ti1);
// Display status
System.out.print("da_ti2.isBefore(da_ti1): ");
System.out.println(status);
}
}
Output
输出量
LocalDateTime da_ti1 and da_ti2:
da_ti1: 2005-10-05T10:10:10
da_ti2: 2020-06-06T21:06:23.203685
da_ti1.isBefore(da_ti2): true
da_ti2.isBefore(da_ti1): false
翻译自: https://www.includehelp.com/java/localdatetime-isbefore-method-with-example.aspx
java 根据类名示例化类