Results 1 to 6 of 6
  1. #1
    java4ever is offline Member
    Join Date
    Mar 2014
    Posts
    3
    Rep Power
    0

    Question Date Parsing Issues with TZ ?

    Hi Experts,

    I have a date in the following String format "2013-03-28,19:37:52.00+00:00" and post processing I am converting this to following String as per prevailing logic to "2013-03-28,19:37:52.00+0000" ( ":" being removed and this is existing code and no changes have been made here for last few years)

    And am using this SDFormat i.e new SimpleDateFormat("yyyy-MM-dd,HH:mm:ss.Sz") for conversion to Date Object

    We are suddenly getting this exception now can't figured out what has changed ?
    Java Code:
    java.text.ParseException: Unparseable date: "2013-03-28,19:37:52.00+0000"
    at java.text.DateFormat.parse(DateFormat.java:357)
    Kindly suggest.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,912
    Rep Power
    5

    Default Re: Date Parsing Issues with TZ ?

    I am still uncertain what you are trying to do. Please provide a Short, Self Contained, Correct Example that shows how the date exists, how you want to parse it and what you want to end up with (including any generated errors).

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    java4ever is offline Member
    Join Date
    Mar 2014
    Posts
    3
    Rep Power
    0

    Default Re: Date Parsing Issues with TZ ?

    Input String="2013-03-28,19:37:52.00+0000"

    We have this SDF - "yyyy-MM-dd,HH:mm:ss.Sz", Which was working previously and now for some reason is giving the exception as shown above and failing to parse the date

    Java Code:
    Date dt = new Date();
    		
    		try {
    			dt = alert.parse("yyyy-MM-dd,HH:mm:ss.Sz");    alert is a String holding the value shown in input string
    		} catch (ParseException e) {
    			
    			e.printStackTrace();  //Code ends up here and throws the error shown above in Original post
    		}

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,912
    Rep Power
    5

    Default Re: Date Parsing Issues with TZ ?

    At least for Java 1.7+, your format is incorrect. The following works:

    Java Code:
          Date dt;
          String alert = "2013-03-28,19:37:52.00+0000";
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd,HH:mm:ss.SSZ");
          try {
             dt = sdf.parse(alert); //   alert is a String holding the value shown in input string
             System.out.println(sdf.format(dt));
          } catch (ParseException e) {
              
             e.printStackTrace();  //Code ends up here and throws the error shown above in Original post
         }
    When you say it worked before, how long ago was that? What version of Java were you using? Did you check to see if any bugs were reported?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    java4ever is offline Member
    Join Date
    Mar 2014
    Posts
    3
    Rep Power
    0

    Default Re: Date Parsing Issues with TZ ?

    Jim ,
    First of all thank you for your prompt response on the same, this does truly resolve the issue.
    We have this code running since 2012 on Java 6 and did not encounter this issue as we persist the records in a DB which has the correct dates till recently.

    We started noticing this in the server.out logs as we had missed to put a logger(log4j) around it,
    We checked for previous logs and other possible scenarios but we are unable to see what changed apart from JDK which was moved to 1.7.0_u51


    Thanks,
    j4r

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,912
    Rep Power
    5

    Default Re: Date Parsing Issues with TZ ?

    I get the same behavior using Java 1.6.0_25.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Date parsing
    By Hemanth Kumar in forum New To Java
    Replies: 4
    Last Post: 03-15-2012, 10:53 AM
  2. Issues with parsing huge file
    By aneuryzma in forum New To Java
    Replies: 2
    Last Post: 03-29-2011, 04:02 AM
  3. Parsing Java Date
    By Sno in forum New To Java
    Replies: 3
    Last Post: 11-24-2010, 05:06 PM
  4. parsing date problem
    By jackjosh_in in forum Advanced Java
    Replies: 7
    Last Post: 05-21-2010, 03:06 PM
  5. parsing date
    By jackjosh_in in forum New To Java
    Replies: 2
    Last Post: 05-21-2010, 02:07 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
  •