Solved

String To Java.util.date

Posted on 2003-12-05
3
391 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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…

632 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