Solved

String To Java.util.date

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet example 11 40
Custom Java Application connects to database: Which one of the 20? 4 27
How do I remove an object from a 3 23
Java: anonymous class 4 17
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)
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 will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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 …

808 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