Results 1 to 8 of 8
  1. #1
    jackjosh_in is offline Member
    Join Date
    May 2010
    Posts
    5
    Rep Power
    0

    Default parsing date problem

    import java.text.SimpleDateFormat;

    String dd = "2006-10-20T1350"

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HHmm");


    sdf.format( dd );

    Iam getting problem with above code
    pls tell me how to parse date

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by jackjosh_in View Post
    import java.text.SimpleDateFormat;

    String dd = "2006-10-20T1350"

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HHmm");


    sdf.format( dd );

    Iam getting problem with above code
    pls tell me how to parse date
    You should make the SimpleDateFormat object parse( ... ), not format( ... ); it parses Strings and format Dates.

    kind regards,

    Jos

  3. #3
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by JosAH View Post
    You should make the SimpleDateFormat object parse( ... ), not format( ... ); it parses Strings and format Dates.

    the problem is the T in the String dd, even with parse. to get around i used dd.replaceFirst("T", " ") and the output was "Fri Oct 20 13:50:00 CEST 2006"

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by j2me64 View Post
    the problem is the T in the String dd, even with parse. to get around i used dd.replaceFirst("T", " ") and the output was "Fri Oct 20 13:50:00 CEST 2006"
    No, note the single quotes around the capital T in the format String.

    kind regards,

    Jos

  5. #5
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    ok, if the T is omitted, you can simply use

    Java Code:
    		String dd = "2006-10-20 1350";
    		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HHmm"); 
    		Date date = (Date)formatter.parse(dd);

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Double post locked. OP, please do not double post the same question in multiple fora.

  7. #7
    jackjosh_in is offline Member
    Join Date
    May 2010
    Posts
    5
    Rep Power
    0

    Default

    ok & thank u all

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by j2me64 View Post
    ok, if the T is omitted, you can simply use

    Java Code:
    		String dd = "2006-10-20 1350";
    		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HHmm"); 
    		Date date = (Date)formatter.parse(dd);
    That 'T' is not the problem, it is properly quoted; the OP needed to parse( ... ) the String, not format( ... ) the String.

    kind regards,

    Jos

Similar Threads

  1. parsing date
    By jackjosh_in in forum New To Java
    Replies: 2
    Last Post: 05-21-2010, 01:07 PM
  2. Parsing Problem in Java
    By vidya in forum Advanced Java
    Replies: 4
    Last Post: 02-01-2010, 03:48 PM
  3. Parsing Problem in Java
    By vidya in forum New To Java
    Replies: 2
    Last Post: 02-01-2010, 01:52 PM
  4. Replies: 0
    Last Post: 06-28-2008, 04:54 AM
  5. parsing problem
    By Pooja Deshpande in forum Advanced Java
    Replies: 4
    Last Post: 05-29-2008, 01:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •