Solved

String To Java.util.date

Posted on 2003-12-05
3
383 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

744 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

15 Experts available now in Live!

Get 1:1 Help Now