String to Date conversion issue
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: String to Date conversion issue

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Posts
    1

    Question 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 ?

    The 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
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: String to Date conversion issue

    The problem is with your format string, it should be:

    Code:
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'");
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center