Thread: Date conversion

    #1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    19
    Rep Power
    0

    Date conversion


    how do i do a check to see if the string (in this case the date) user entered is in YYYY-MM-DD format. if it is not in this format, then it should convert to this format.

    eg: user entered 16-09-2002, it should be converted to 2002-09-16.

    however if the user entered 2002-09-16, then no conversion is needed.

    pls help asap..
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Use http://java.sun.com/j2se/1.4/docs/ap...mat.html#parse(java.lang.String) then spit the date out however you want.
  4. #3
  5. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    19
    Rep Power
    0
    i dun really understand what the website is trying to do. can you show me the codes??
  6. #4
  7. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Code:
    dateString = new SimpleDateFormat( "yyyy-MM-dd" ).format( new SimpleDateFormat.parse( "16-09-2002" ) );
    You'll need to import java.text.SimpleDateFormat.
  8. #5
  9. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    19
    Rep Power
    0
    how come i get this error: Class java.text.SimpleDateFormat. parse not found, even though i have imported the SimpleDateFormat class???
  10. #6
  11. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Sorry,
    Code:
    new SimpleDateFormat.parse( "16-09-2002" )
    should be
    Code:
    new SimpleDateFormat().parse( "16-09-2002" )

IMN logo majestic logo threadwatch logo seochat tools logo