Solved

String To Java.util.date

Posted on 2003-12-05
3
384 Views
Last Modified: 2010-03-31
Hi
I want to transforme a string to a date, so what i did is :

// x is my string
DateFormat myDateFormat = new SimpleDateFormat("yyyyMMdd");
java.util. date myDate = myDateFormat.parse(x);


It worked fine until I entered a invalid date.  ex x = 20039999
That date was transform to 20120607.  It's a valid date, BUT not the one that I entered.

Is there a way to thow a exception if the date enter ( x ) is incorrect

Thanks in advance
0
Comment
Question by:pchaloux
  • 3
3 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 9883767
myDateFormat.setLenient(flase);
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 9883772
Woops ;-)

myDateFormat.setLenient(false);
     
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9884233
8-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
base64 decode encode 12 121
JDeveloper 12c for 32 bit 4 71
Oracle SQL syntax check  without executing 6 36
javap not working 8 37
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now