Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default String to date conversion issue...

    Hi,
    I am trying to convert the string date to actual date using SimpleDateFormat class. But it seems the SimpleDateFormat class is returning the invalid value for the date object. It is increasing the minute value by 1. I am not sure if it's an actual issue with SimpleDateFormat class or my way of conversion is wrong. Any Help is really appreciated.

    The code :

    Java Code:
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.ms'Z'");
    Date date = dateFormat.parse("2011-12-20T15:08:14.917Z");
    
    System.out.println("Date: " + date);
    
    It is displaying "Tue Dec 20 15:09:17 IST 2011" instead of "Tue Dec 20 15:08:14 IST 2011".
    Thanks in advance.

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

    Default Re: String to date conversion issue...

    Does that happen consistently or did it only happen once?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default Re: String to date conversion issue...

    Hi Jos,
    It's happening every time. Any idea why ?

    Thanks.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: String to date conversion issue...

    It parses the .ms at the end as 9:17

  5. #5
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default Re: String to date conversion issue...

    any other way or method which gives me proper date ?

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: String to date conversion issue...

    Don't put the .ms there. Or, if you want milliseconds, consult the SimpleDateFormat API docs and see what the code for them is.

Similar Threads

  1. string date to formatted date string
    By reach2sudhakar in forum New To Java
    Replies: 4
    Last Post: 06-20-2011, 11:06 AM
  2. String to date conversion
    By nn12 in forum New To Java
    Replies: 4
    Last Post: 11-04-2010, 08:59 AM
  3. converting string (GMT date) to date in US time.
    By JRuyechan in forum New To Java
    Replies: 1
    Last Post: 10-15-2010, 08:07 AM
  4. convert String date to Date
    By computerbum in forum New To Java
    Replies: 7
    Last Post: 09-18-2010, 04:26 PM
  5. String to Date conversion
    By javaplus in forum New To Java
    Replies: 2
    Last Post: 11-06-2007, 08:16 PM

Tags for this Thread

Posting Permissions

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