• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String to Date

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all
when iam parsing String into Date it is throwing

java.text.ParseException: Unparseable date: "12-03-2000"

please explain

import java.util.Date;
import java.text.DateFormat;
public class DateDemo{
public static void main(String sai[]){
String s="12-03-2000";
DateFormat df = DateFormat.getDateInstance();
Date d=null;
try{
d = df.parse(s);

}catch(java.text.ParseException pe){
System.out.println(pe);
}


}
}
thanks in advance
saiprasanna
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Please try this to parse your String date to Date Object.

Date dateReturned = null;

try {
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
"MM-dd-yyyy");
dateReturned = sdf.parse(s);
} catch (Exception e) {
System.out.println("Exception is" + e.getMessage());
}
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Recall that getDateInstance "Gets the date formatter with the default formatting style for the default locale". It seems this is not what you are expecting with your date string "12-03-2000". Heck, I don't know if that's December 3 or March 12! (Me, I stick to the Mayan calendar ) Take a peek at your DateFormatter's pattern:
 
sai prasanna
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all

why we are not able to parse String to Date by using DateFormat.

Can any one give me the DateFormatter's pattern url.

thanks in advance
saiprasanna
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My post just did. If you want to use a specific format, versus the "default", check out SimpleDateFormat.
 
reply
    Bookmark Topic Watch Topic
  • New Topic