📌  相关文章
📜  Java中的 DateFormat isLenient() 方法及示例

📅  最后修改于: 2022-05-13 01:55:21.441000             🧑  作者: Mango

Java中的 DateFormat isLenient() 方法及示例

DateFormat 类中的isLenient()方法用于了解和理解对这个 DateFormat 对象的日期和时间的解析是否被认为是宽松的。

句法:

public boolean isLenient()

参数:该方法不带任何参数。

返回值:如果此日历的解释宽松,则该方法返回 True,否则返回 False。

下面的程序说明了 Calendar 类的 isLenient() 方法的工作原理:
示例 1:

// Java code to illustrate
// isLenient() method
  
import java.text.*;
import java.util.*;
  
public class DateFormat_Demo {
    public static void main(String[] args)
    {
        // Initializing the first formatter
        DateFormat DFormat
            = DateFormat.getDateTimeInstance();
        System.out.println("Object: "
                           + DFormat);
  
        // String formatting
        String str
            = DFormat.format(new Date());
  
        // Displaying the string time
        System.out.println(str);
  
        System.out.println("Leniency: "
                           + DFormat.isLenient());
    }
}
输出:
Object: java.text.SimpleDateFormat@7945516e
Mar 28, 2019 4:23:01 AM
Leniency: true

示例 2:

// Java code to illustrate
// isLenient() method
  
import java.text.*;
import java.util.*;
  
public class DateFormat_Demo {
    public static void main(String[] argv)
    {
        // Initializing the first formatter
        DateFormat DFormat
            = DateFormat.getDateInstance();
        System.out.println("Object: "
                           + DFormat);
  
        // String formatting
        String str
            = DFormat.format(new Date());
  
        // Displaying the string time
        System.out.println(str);
  
        System.out.println("Leniency: "
                           + DFormat.isLenient());
    }
}
输出:
Object: java.text.SimpleDateFormat@ce9bf0a5
Mar 28, 2019
Leniency: true

参考: https: Java/text/DateFormat.html#isLenient()