Java DateFormat: setLenient(boolean lenient)� Example.

Java DateFormat: setLenient(boolean lenient)� Example.


Posted in : Core Java Posted on : December 3, 2010 at 4:41 PM Comments : [ 0 ]

Java DateFormat: setLenient(boolean lenient)� Example.

Java DateFormat: setLenient(boolean lenient) Example.

In this example, you will see the use of isLenient() method of DateFormat class.

This method specifies whether or not date/time parsing is to be lenient. With lenient parsing, the parser may use heuristics to interpret
inputs that do not precisely match this object's format. With strict parsing, inputs must match this object's format.

Code:
IsLenientDemo.java
import java.text.DateFormat;
import java.util.Date;

public class IsLenientDemo {
public static void main(String[] args) {

	// Create date object with current value.
	Date date = new Date();
	System.out.println("Current value of date : " + date.toString());

	// Create a object of DateFormat with default date/time.
	DateFormat dateFormat = DateFormat.getInstance();
	String stringDate = dateFormat.format(date);
	System.out.println("Date in default format : " + stringDate);
	
	// check Date/time is lenient or not.
	boolean bool = dateFormat.isLenient();
	System.out.println("Date/time is lenient : " + bool);
	}
}
Output
Current value of date : Fri Dec 03 14:46:18 GMT+05:30 2010
Date in default format : 12/3/10 2:46 PM
Date/time is lenient : true
Download this code..
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics