import java.util.Date;
import java.text.ParseException;
import java.text.DateFormat;
public class validateDate
{
public static void main(String args[])
{
String dt = "04/31/2005"; //Invalid Date
//String dt = "02/29/2004"; //Valid Date
try
{
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
df.setLenient(false); // this is important!
Date dt2 = df.parse(dt);
System.out.println("Date is ok = " + dt2);
}
catch (ParseException e)
{
System.out.println("Invalid date " + dt);
}
catch (IllegalArgumentException e)
{
System.out.println("Invalid date " + dt);
}
}
}//End of validateDate
Thursday, February 28, 2008
Sample Code On Simple Date Validation
Labels:
programming
Subscribe to:
Post Comments (Atom)
Archives
-
▼
2008
(35)
-
▼
February
(35)
- How To Make http To https Request
- User With Password Never Expires on MS-Adam
- Sample Code On Use XML in Java to Write Save Docum...
- Sample Code On Random Sentence Generator
- Sample Code On How To Send Email Using Java Mail
- Keeping a Standard Coding Template
- Sample Code On How to Upload a File and How to Sto...
- Sample Code On Example Uses Of Calendar Class
- Sample Code On How to Get the Start Date of the We...
- How to Make a Java Class Immutable
- Simple Program for Reading Writing Content From File
- Code for Java-Mail
- Sample Code On Simple Date Validation
- Sample Code On Cows and Bulls Game
- Sample Code On BasicDateFormatting.java
- Sample Code On TTSTest.java
- Sample Code On Process Execution
- Sample Code On Read Contents Of URL
- Sample Code On XMLParserUtils
- Sample Code On Bin.java
- Sample Code On ASCII_code
- Sample Code On Prime
- Sample Code On Factorial
- A Serializable JButton
- A Java Calculator
- The example draws several moving wadges on a circle
- Demonstrate Boolean Values
- StackDemo shows how to use the linear set of objects
- Hide Password From Command Line
- Input through Keyboard
- Assertion in Java
- String in Java
- Variable and Expressions
- A Simple HelloWorld.java program
- History of Java
-
▼
February
(35)
No comments:
Post a Comment