Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

String To Java.util.date

Posted on 2003-12-05
3
Medium Priority
?
392 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 800 total points
ID: 9883772
Woops ;-)

myDateFormat.setLenient(false);
     
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9884233
8-)
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

705 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