Results 1 to 1 of 1
- 10-04-2007, 09:31 PM #1
How to validate date using SampleDateFormat
This sample program will show the use of SampleDateFormat for validating the date for a particular format.
Java Code:import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class ValidationExp { public static void main(String[] args) { String pattern = "dd/MM/yy"; SimpleDateFormat sdf = new SimpleDateFormat(); String strDate = "29/07/06"; try { sdf.applyPattern(pattern); Date date =sdf.parse(strDate); System.out.println("Date :- " + date); } catch (ParseException e) { System.out.println("Wrong date format"); e.printStackTrace(); } } }
Similar Threads
-
Difference between current date and anothe date
By vijay balusamy in forum New To JavaReplies: 1Last Post: 04-16-2008, 04:15 PM -
How to validate date using SampleDateFormat
By Java Tip in forum java.textReplies: 0Last Post: 04-04-2008, 02:38 PM -
repaint validate doLayout
By Gajesh Tripathi in forum AWT / SwingReplies: 1Last Post: 10-27-2007, 06:53 PM -
how to validate a xml file with schemas via SAX
By oregon in forum XMLReplies: 3Last Post: 08-01-2007, 05:15 PM -
validate hex character
By paul in forum New To JavaReplies: 1Last Post: 07-25-2007, 09:08 PM
Bookmarks