Results 1 to 3 of 3
  1. #1
    vpillai is offline Member
    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    Default how to parse this string to SimpleDateFormat

    I have the date in string format, read as "2011-08-11T17:25:36-04:00". How can I parse this into a SimpleDateFormat?

    I tried this but it says Unparseable date: "2011-08-11T17:25:36-04:00"

    String s = "2011-08-11T17:25:36-04:00";

    java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-ddEkk:mm-ss:SS");

    try{
    Date dateDB = df.parse(s);
    }
    }catch(Exception e){System.out.println(e.getMessage());}

    Can someone help me with this??

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    1. The timestamp does not match

    2. For day in week (E) you have T. Is that Tuesday or Thursday? Would S be Saturday or Sunday? If you read the API the minimum for day in week is 3 letters: Sun, Mon, Tue etc.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    Yes, that 'T' is simply a divider to show where the time starts.
    So it should appear in your format as a 'T', not an 'E'.

    And as Junky says, your timestamp is incorrect.
    The bit from the '-' to the end is the UTC offset (GMT+/-X).

Similar Threads

  1. parse xml string
    By awallace in forum Java Applets
    Replies: 1
    Last Post: 07-27-2011, 02:01 PM
  2. parse simple string with regex?
    By zardos in forum New To Java
    Replies: 1
    Last Post: 03-01-2011, 12:14 PM
  3. Trying to parse int from string. Need help please.
    By Romally in forum New To Java
    Replies: 4
    Last Post: 11-14-2010, 09:58 PM
  4. how to Parse int to a string variable
    By raj reddy in forum Java Servlet
    Replies: 10
    Last Post: 01-09-2009, 07:41 PM
  5. how to Parse int to a string variable (pls hlp)
    By raj reddy in forum Threads and Synchronization
    Replies: 5
    Last Post: 06-10-2008, 06:32 AM

Posting Permissions

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