This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

using parse() from DateFormat  RSS feed

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I have a basic question reg validating a date.

Pl go thru the sample program

public static void main(String[] args) {
Date dtParsedDate = null;
DateFormat dtFormattedDate = null;
try{
dtFormattedDate = new SimpleDateFormat("mm/dd/yyyy");//1
dtParsedDate = dtFormattedDate.parse("20/05/2005");//2
System.out.println(dtParsedDate);//3
System.out.println("Correct Date");
}catch(ParseException ex){
System.out.println("Incorrect Format" + ex.getMessage());
}
}

here when i am running the program, it gives me the output as "Correct Date"
at step 1, when i give the format as
dtFormattedDate = new SimpleDateFormat("MM/DD/YYYY");
then even if i enter the correct date for ex: 02/12/2005, even then it gives me the output saying Incorrect Format.
I am not able to understand what does parse() doing.
Also at step3, dtParsedDate displays wrong date. It doesn't print the input that i give

Can any one pl explain me about the parse() and the difference between the formats in "mm/dd/yyyy" and "MM/DD/YYYY" in step 1.

Thanks very much for your time
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, look the API for class SimpleDateFormat.

Letter Date or Time Presentation Examples
y Year Year 1996; 96
M Month in year Month July; Jul; 07
m Minute in hour Number 30
D Day in year Number 189
d Day in month Number 10
 
Vishnu Munnangi
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply.
 
If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!