1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

SimpleDateFormat

Discussion in 'Java' started by majorpayne27, Aug 21, 2007.

  1. majorpayne27

    majorpayne27 New Member

    Joined:
    Jul 11, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I apologize for this noob-level question, but I'm angry at SimpleDateFormat and am wondering in anyone knows how to make it do what I want.

    My issue is that I'm using SimpleDateFormat to basically validate different types of dates. This usually works fine, except with the terminating field of a date. For example, I parse the String "08/21/2007" against the format "MM/dd/yyyy" and confirm the date is valid.

    My problem occurs when the user enters "bad" data for the year. If non-valid character are put in the month or date fields, they are handled with an error perfectly fine. However, if the user enters a letter somewhere in the year (say they use the letter O instead of a zero) SimpleDateFormat just views it as a terminating character. In short, the string "08/27/2OO7" (with letter O's) is parsed to "08/27/2" when it should be throwing an error. Is there any way to force SimpleDateFormat's parse to check the entire string?
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:

Share This Page